473,396 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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!
Nov 18 '05 #1
2 986

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 goingwrong? 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 foryour help!
.

Nov 18 '05 #2

"Mark Fox" <in**@solelsoftware.com> wrote in message
news:06****************************@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;
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
0
by: Bart | last post by:
Hello, I am real new to using LIBXML and have a question about XPATH evaluations. The question may show a real ignorance of the LIBXML structure, don't so assume I know what I am talking about....
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
7
by: Tim Hallwyl | last post by:
Hi, there! As I understand the XPaht recommendation, the context node is a node; not a node-list, not XPath object -- but a single node. Now, the WS-BPEL 2.0 specification allows an XML simple...
0
by: pompair | last post by:
Hello, I'm making a quiz game for fun. I have an xml file like this: <?xml version="1.0" encoding="utf-8" ?> <results> <index>99</index> <answers>11</answers> <questions> <question id="1">
0
by: John Krukoff | last post by:
On Wed, 2008-09-03 at 13:36 -0700, bruce wrote: Well, you could just do the test (and the count!) in the xpath expression: count( //tr/td ) It sounds like you're not familiar with xpath? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.