blur
blur

Reputation: 1

reading xmls with xpath

I need to read this xml to get values like "Simpson" for example,

<?xml version="1.0"?>
<Example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Header>
        <Data Name="LastName">Simpson</Data>
        <Data Name="IdPeople">4355</Data>
        <Data Name="State" />
        <Data Name="City" />
        <Data Name="Requests">12</Data>
    </Header>
    <Body />
 </Example>

I do this frequently and want to use efficient code, maybe xpath is the best approach?? Some samples??

Upvotes: 0

Views: 81

Answers (1)

Ed Manet
Ed Manet

Reputation: 3178

To get the last name, the xpath would be something like this:

/Example/Header/Data[Name='LastName']

To get the number of Requests:

/Example/Header/Data[Name='Requests']

Upvotes: 2

Related Questions