Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Node Value & Child node define together?

Status
Not open for further replies.

PankajAgr

Technical User
Jul 30, 2003
52
0
0
IN
Hi Guys,

I design one XML in following format-

<PNode> Top Node
<CNode>Child Node </CNode>
</PNode>

I want to know can we define the node value & child node together within one node? I checked this XML in XMLspy it is returning a well formed XML.

If yes then how to read the value of the node <A> through DOM parser.

Please sugget me some solution.

Thank in advance
Pankaj

Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
Yes, it is valid XML, but I'd say don't use it as it is needlessly confusing.

If you have:
<A>aaaa<B>bbbb</B></A>
then
<xsl:value-of select="//A"/> would give 'aaaabbbb'
while
<xsl:value-of select="//A/text()"/> would give 'aaaa'.
 
Hi Jel,

Thanks, to give me this information. But, I want to know how to acess the node value through DOM object. I am using the VB6 with Micosoft XML-3.0 for DOM.

When I creat the DOM object and accessing the value, it is giving following output -
XML-
<PNode> Top Node
<CNode>Child Node </CNode>
</PNode>

Output-

omsDOM.NodeName PNode
omsDOM.Text Top Node Child Node
omsDOM.NodeValue Null

Why node value is returning null not a 'Top Node' value?

Thanks and Regards

Pankaj








Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
Well, as I said: it is confusing.
In X-path (which is the query-languge you use in XSL as well as in the DomDocument.SelectNodes(...) function) there are two nodes: PNode and CNode.
However: PNode does contain 2 things, text and CNode.
Therefore, MSXML makes 2 childnodes instead of one.
Try this:
Code:
Dim domDoc As New MSXML2.DOMDocument40
Dim ndeSub As IXMLDOMNode

domDoc.loadXML ("<root><PNode>Top<CNode>Child</CNode></PNode></root>")
For Each ndeSub In domDoc.selectSingleNode("//PNode").childNodes
    Debug.Print ndeSub.Text
Next
The tricky part is, that you cannot get to the first (text)subnode using selectSingleNode(...): according to x-path there is no extra childnode.

The reason that NodeValue returns Null is that that property is meant for node-types text, comment, attribute etc (see documentation) and the node-type of your PNode is 'element'.

So: spare yourself a lot of trouble and use this structure:
<PNode>
<Content>Top Node</Content>
<CNode>Child Node</CNode>
</PNode>


 
Thanks jel for this valuable responce,

I understand your point if we define the node value & child node together then DOM object treat node value as a child node.

I updated my code, now It is working fine.


Senior Software Engineer,
Infotech Enterprises Limited
Hyderabad, Andhra Pradesh, India.
URL :
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top