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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Attribute Value in XML

Status
Not open for further replies.

dtr333

Programmer
Jun 1, 2010
2
US
Hi there,

I have the following sample xml:

<Questions>
<Are-You-Pregnant answer="N"/>
<Are-You-Male answer="Y"/>
<co-current-continue answer="Y"/>
<co-covered-by-medicare answer="Y"/>
</Questions>

What is the XPath Expression that i need to get the answer = Y or N?
Eg: /Questions/Are-You-Pregnant[@anwer]

I have to rewrite the xml to the following format?

<Question>
<Pregnant>N</Pregnant>
<Male>N</Male>
</Question>

Using what xpath expression can i get the attribute value?

Thanks..
 
[tt]/Questions/Are-You-Pregnant/@answer
/Questions/Are-You-Male/@answer
/Question/Pregnant
/Question/Male[/tt]
 
I have tried using this but didnot work. I also have some prefixes in my XML as shown below: What if there are prefixes involved. How would the Xpath exp be?

Sample Xml

<app:Questions>
<app:Are-You-Pregnant answer="N"/>
<app:Are-You-Male answer="Y"/>
<app:co-current-continue answer="Y"/>
<app:co-covered-by-medicare answer="Y"/>
</app:Questions>

I appreciate your help in this regard.

Thanks..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top