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!

XML Structural question...

Status
Not open for further replies.

Snaggs

Programmer
Jan 11, 2000
393
0
0
US
We have the following XML sturcture:<br><br>&lt;TCAResult&gt;<br> &lt;TCACall&gt;<br> &lt;CallID&gt;1&lt;/CallID&gt;<br> &lt;ConsumerID&gt;1111&lt;/ConsumerID&gt;<br> &lt;DateAndTime&gt;01/01/2000 11:52 AM&lt;/DateAndTime&gt;<br> &lt;OperatorCode&gt;AB1&lt;/OperatorCode&gt;<br> &lt;/TCACall&gt;<br> &lt;TCACall&gt;<br> &lt;CallID&gt;2&lt;/CallID&gt;<br> &lt;CallerComment&gt;BBB&lt;/CallerComment&gt;<br> &lt;ConsumerID&gt;2222&lt;/ConsumerID&gt;<br> &lt;DateAndTime&gt;02/01/2000 11:52 AM&lt;/DateAndTime&gt;<br> &lt;OperatorCode&gt;AB2&lt;/OperatorCode&gt;<br> &lt;/TCACall&gt;<br> &lt;TCACall&gt;<br> &lt;CallID&gt;3&lt;/CallID&gt;<br> &lt;CallerComment&gt;CCC&lt;/CallerComment&gt;<br> &lt;ConsumerID&gt;3333&lt;/ConsumerID&gt;<br> &lt;DateAndTime&gt;03/01/2000 11:52 AM&lt;/DateAndTime&gt;<br> &lt;OperatorCode&gt;AB3&lt;/OperatorCode&gt;<br> &lt;/TCACall&gt;<br> &lt;ResultCode&gt;0&lt;/ResultCode&gt;<br>&lt;/TCAResult&gt;<br><br>If you notice, the first Node is missing the &lt;CallerComment&gt; tag.&nbsp;&nbsp;My question is this:<br><br>If you're iterating through the list of Nodes in the xml structure, do all nodes have to have the same tags.&nbsp;&nbsp;The reason I ask is that with the tag missing in the first Node, the MSXML parser jumps down to the second node and grabs its &lt;CallerComment&gt; and uses it for the first Node's caller comment.&nbsp;&nbsp;Then the last caller comment is blank.&nbsp;&nbsp;I don't think it should work this way, but then maybe I don't know all the rules dealing with XML.&nbsp;&nbsp;If I put an empty tag in for &lt;CallerComment/&gt; (&lt;--Like that) for the first record then the document parses correctly.&nbsp;&nbsp;If anyone has any information on this topic I'd like it if you would post a reply.<br><br>Sample output for the first node:<br><br>CallID=1<br>CallerComment=BBB&nbsp;&nbsp;&lt;-- This should be blank, not BBB.<br>ConsumerID=1111<br>DateAndTime=01/01/2000 11:52 AM<br>OperatorCode=AB1<br><br>Thanks, <p>Steve<br><a href=mailto:tribesaddict@swbell.net>tribesaddict@swbell.net</a><br><a href= > </a><br>
 
Dear Steve,<br><br>I can't state this with any certainty, nor can I provide an example. But I believe you can write a DTD for your document that defines the &lt;CallerComment&gt; entity as 'optional'. That might be the technique you are looking for.<br><br>Good luck<br>-pete
 
Pete,<br><br>Thanks for the response, but I figured out what was wrong with the approach.&nbsp;&nbsp;I figured I'd share it with others before they make the same mistake.<br><br>We were using GetElementByName off the DOM.&nbsp;&nbsp;However, when you use this, it references the elements from the document level and not the node level.&nbsp;&nbsp;This make perfect sense when you stop and think about it.&nbsp;&nbsp;When you tell it to get the Element by name, it get's the first one, regardless of the node it resides under.&nbsp;&nbsp;What we had to do was get the node and then look at the child nodes.&nbsp;&nbsp;Then the CallerComment tag would not show up in the ChildNodes where they didn't exist.<br><br>Now it works great and gives us the expected results.<br> <p>Steve<br><a href=mailto:tribesaddict@swbell.net>tribesaddict@swbell.net</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top