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 June 8th, 2006, 05:52 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default extract attribute value xPath

hi,

simple question I guess but I couldn't find the answer...
How to extract the value of an attribute using xPath?

for example, lets say this is the xml:
<root>
        <classes>
                <class>
                        <lesson id="55" />
                        <lesson id="66" />
                        <lesson id="88" />
                </class >
        </classes>
</root>

and I want the output to be :
55
66
88

so the path should be: ...xmlDoc.selectNodes(/classes/class/lesson/???)
and I dont know what should be instead of the ???
(@id will bring back: id="55" while I need only 55)
Thanks

Janiv
 
Old June 9th, 2006, 01:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

/classes/class/lesson/@id returns the attribute nodes. You can then extract the values of the attribute nodes in your calling application, using getNodeValue() or whatever the DOM method is called.

XPath 1.0 doesn't have a data type for a set of strings, so you can't write an XPath 1.0 expression that returns a set of strings. In XPath 2.0 you can write

/classes/class/lesson/@id/string()



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 4th, 2011, 07:09 PM
Registered User
 
Join Date: Apr 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
extract string from value of attribute camacho XSLT 1 August 16th, 2007 02:44 AM
Use xPath to test for an absent/missing attribute NitroxDM XSLT 3 June 13th, 2007 09:00 AM
How to use Xpath to extract child nodes smilysuresh XSLT 3 February 23rd, 2007 06:32 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM
XPath - Selecting nodes based on attribute values billy_bob_the_3rd XML 4 December 1st, 2004 06:12 PM





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