简体   繁体   中英

XPath for parsing XML attributes

Can someone please tell me the "correct / most-efficient way" of getting the "Status" XML attributes (ID, CssClass, Description, and IsActive for the XML below:

Implementation will be Java - (but I am more interested in the XPath):

<ArrayOfLineStatus>
<LineStatus ID="0" StatusDetails="">
    <BranchDisruptions/><Line ID="1" Name="Bakerloo"/>
    <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">          
    <StatusType ID="1" Description="Line"/></Status></LineStatus>
[snip]
 </ArrayOfLineStatus>

Thank,

Miles.

@* selects all attributes of the context node. Use:

/*/*/Status/@*

Or, more specifically:

/ArrayOfLineStatus/LineStatus/Status/@*

Or, for Status elements appearing anywhere in the document:

//Status/@*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM