Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   XML XPath Question (http://www.velocityreviews.com/forums/t66776-xml-xpath-question.html)

Mark Fox 11-15-2003 12:36 AM

XML XPath Question
 
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!

Mark Fox 11-15-2003 12:53 AM

XML XPath Question
 

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!
>.
>


Bret Mulvey [MS] 11-15-2003 12:57 AM

Re: XML XPath Question
 

"Mark Fox" <info@solelsoftware.com> wrote in message
news:062901c3ab10$8e7ae130$a101280a@phx.gbl...
> 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;




All times are GMT. The time now is 04:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.