Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > XML XPath Question

Reply
Thread Tools

XML XPath Question

 
 
Mark Fox
Guest
Posts: n/a
 
      11-15-2003
Hello,

I have some XML loaded into an XmlDocument and
attempting to figure out how to access certain nodes. I
assume I should use XPath, but I am having trouble
getting the XPath syntax correct. Where might I be going
wrong? Any help would be appreciated!

XML:

<Reason>

<ReasonCategory>Death</ReasonCategory>
<Contacts>
<Contact>
<Name></Name>
<Phone></Phone>

<Address></Address>

<CityStateZip></CityStateZip>

<Relation></Relation>

<IsMember></IsMember>
</Contact>
</Contacts>
<ReasonDetails>

<PlaceOfDeath></PlaceOfDeath>

<CauseOfDeath></CauseOfDeath>

<FuneralLocationName></FuneralLocationName>

<FuneralDateTime></FuneralDateTime>

<FuneralFoodRequirements></FuneralFoodRequirements
>

<ReasonDetails>
<RequestedServices>
<RequestedService>

<OfferedServiceName></OfferedServiceName>

<AssignedTo></AssignedTo>
</RequestedService>
</RequestedServices>
<FormDetails>

<CompletedBy></CompletedBy>

<CompletedDate></CompletedDate>
<Notes></Notes>
</FormDetails>
</Reason>

I am attempting to access the ReasonCategory node with:

XmlNodeReader myXmlNodeReader = new XmlNodeReader
(myXmlDocument.SelectSingleNode("Reason/ReasonCategory"));
string ReasonCategory =
myXmlNodeReader.Value;

But the XmlNodeReader isn't finding the node. Thanks for
your help!
 
Reply With Quote
 
 
 
 
Mark Fox
Guest
Posts: n/a
 
      11-15-2003

Nevermind, I figured it out. Sorry!


>-----Original Message-----
>Hello,
>
> I have some XML loaded into an XmlDocument and
>attempting to figure out how to access certain nodes. I
>assume I should use XPath, but I am having trouble
>getting the XPath syntax correct. Where might I be

going
>wrong? Any help would be appreciated!
>
>XML:
>
> <Reason>
>
> <ReasonCategory>Death</ReasonCategory>
> <Contacts>
> <Contact>
> <Name></Name>
> <Phone></Phone>
>
> <Address></Address>
>
> <CityStateZip></CityStateZip>
>
> <Relation></Relation>
>
> <IsMember></IsMember>
> </Contact>
> </Contacts>
> <ReasonDetails>
>
> <PlaceOfDeath></PlaceOfDeath>
>
> <CauseOfDeath></CauseOfDeath>
>
> <FuneralLocationName></FuneralLocationName>
>
> <FuneralDateTime></FuneralDateTime>
>
> <FuneralFoodRequirements></FuneralFoodRequirements
>>

> <ReasonDetails>
> <RequestedServices>
> <RequestedService>
>
> <OfferedServiceName></OfferedServiceName>
>
> <AssignedTo></AssignedTo>
> </RequestedService>
> </RequestedServices>
> <FormDetails>
>
> <CompletedBy></CompletedBy>
>
> <CompletedDate></CompletedDate>
> <Notes></Notes>
> </FormDetails>
> </Reason>
>
>I am attempting to access the ReasonCategory node with:
>
>XmlNodeReader myXmlNodeReader = new XmlNodeReader
>(myXmlDocument.SelectSingleNode

("Reason/ReasonCategory"));
> string ReasonCategory =
>myXmlNodeReader.Value;
>
>But the XmlNodeReader isn't finding the node. Thanks

for
>your help!
>.
>

 
Reply With Quote
 
 
 
 
Bret Mulvey [MS]
Guest
Posts: n/a
 
      11-15-2003

"Mark Fox" <(E-Mail Removed)> wrote in message
news:062901c3ab10$8e7ae130$(E-Mail Removed)...
> Hello,
>
> I have some XML loaded into an XmlDocument and
> attempting to figure out how to access certain nodes. I
> assume I should use XPath, but I am having trouble
> getting the XPath syntax correct. Where might I be going
> wrong? Any help would be appreciated!
>
> XML:
>
> <Reason>
>
> <ReasonCategory>Death</ReasonCategory>

etc.
> </Reason>
>
> I am attempting to access the ReasonCategory node with:
>
> XmlNodeReader myXmlNodeReader = new XmlNodeReader
> (myXmlDocument.SelectSingleNode("Reason/ReasonCategory"));
> string ReasonCategory =
> myXmlNodeReader.Value;
>
> But the XmlNodeReader isn't finding the node. Thanks for
> your help!


The "Value" of an XmlElement node is null. What you want is the InnerText.
And instead of using XmlNodeReader you can also use the SelectSingleNode
result directly, e.g.

string ReasonCategory =
myXmlDocument.SelectSingleNode("/Reason/ReasonCategory").InnerText;


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments