Kasper Hansen
Kasper Hansen

Reputation: 6557

How to parse XML without a schema?

I recieve this piece of xml:

<hash>
  <base>XPM</base>
  <alt>BTC</alt>
  <value type="decimal">0.00341</value>
</hash>

How do I get the values of base, alt and value tags? I would also like to know that the type attribute is decimal.

Upvotes: 1

Views: 720

Answers (2)

Vladimir Kniazkov
Vladimir Kniazkov

Reputation: 309

You can use the XPath: Get alt nodes - //hash/alt Get value nodes with type="decimal" - //hash/value[@type="decimal"]

Upvotes: 1

Anirudha
Anirudha

Reputation: 32797

You can use LINQ2XML

XElement node=XElement.Parse(input);
node.Element("base").Value;
node.Element("alt").Value;
node.Element("value").Attributes("type").Value;//attribute value
node.Element("value").Value;

Upvotes: 6

Related Questions