Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2004, 08:05 AM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Duplicate Element Names

I cannot read monsterData. Would someone please take a look
and provide some advice.

Thanks,
Carolyn



XmlNodeList jobPayGradeHi = myDocument.GetElementsByTagName("PayGradeHi");
XmlNodeList jobPayGradeLow = myDocument.GetElementsByTagName("PayGradeLo");
XmlNodeList jobTitles = myDocument.GetElementsByTagName("JobTitle");
XmlNodeList monsterData = myDocument.SelectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/JAFolders/OPM:JAFolder/OPM:JobAnnouncement/OPM:ExpireDate/OPM:Day");

for (int i = 0; i < jobTitles.Count; i++)
        {
           Response.Write(jobPayGradeHi[i].ChildNodes[0].Value);//ok
           Response.Write(jobPayGradeLow[i].ChildNodes[0].Value);//ok
           Response.Write(monsterData[i].Value);//causes an error
        }


Here is part of the xml which I am trying to read. If I rename ExpireDate/Day to ExpireDay, it works fine,
the owner of the file will not rename the elements.

<PayGradeHi>09</PayGradeHi>
<PayGradeLo>05</PayGradeLo>
<JobTitle><Analyst</JobTitle>

<ClosingDate>
<Day>31</Day>
<Month>12</Month>
<Year>2070</Year>
</ClosingDate>

<ExpireDate>
<Day>31</Day>
<Month>12</Month>
<Year>2070</Year>
</ExpireDate>

<OpeningDate>
<Day>18</Day>
<Month>02</Month>
<Year>2004</Year>
</OpeningDate>




 
Old September 30th, 2004, 09:22 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

THis is a little tricky with only a partial document, but...

I assume your SOAP xml document has some namespaces declared in the top.

Your error is probably a null pointer exception of some kind, since monsterData may contain a zero-sized list. In your XPath for monsterData you specify namespace prefixes for SOAP-ENV for the envelope, and OPM for most of your nodes, however on JAFolders you specify no namespace. Is this what you want? If JAFolder does have a namespace then your Xpath will return no matches, hence an empty list.

Try spitting out monsterData.length() or ubound(monsterData) (I'm not totally sure what language you are using) to see the number of nodes in the list.

holdmykidney







Similar Threads
Thread Thread Starter Forum Replies Last Post
remove duplicate text in an output html element mrame XSLT 1 June 20th, 2008 01:41 AM
Element Names - Dashes Suu XML 3 August 2nd, 2007 08:49 AM
Getting form element names in a loop crapanz Javascript 5 January 30th, 2006 12:45 AM
select wildcard element names groovepapa XSLT 4 September 1st, 2004 08:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.