0

I am trying to validate Elements and Attributes exist in an XElement. Basically, I was wondering if anyone had a generic way to check if a give path is null. I don't have access to System.Xml.XPath (doing this for compact framework).

Basically what I have is:

<root value"1000">
  <element1>test<element1>
  <element2>1<element2>
  ....
  <element30>
    <subElement1>stuff</subElement1>
  </element30>
</root>

Now I know you can "if this is null do this and that". But since there is upwards of 30 elements that can be under root, which are optional elements, I need a way to grab the value if it exists and convert it to the correct type (which I know) in a nice compact way.

Any suggestions?

cw.
  • 109
  • 1
  • 7

1 Answers1

0

If all you need to do is validate that the XML document adheres to given rules or format you might want to use XML Schema for that rather than LINQ.

Cornelius
  • 3,526
  • 7
  • 37
  • 49
  • They don't exist in the SDK. No Schemas, no xpath... Really not much of anything. – cw. Mar 24 '10 at 12:14