flockofcode
flockofcode

Reputation: 1819

XElement weirdness

XML Schemas allow us to exercise greater control over textual content in text-only elements by providing built-in datatypes ( string,byte,int... ):

<xs:element name="root" type="xs:int"></xs:element>

But how do we create the above element using XElement class? Namely, if we pass to XElement's constructor an int value ( say 20 ) representing element's content, this value will be converted to a string ( ie XText instance ) and treated as such:

      int int1 = 20;
      XElement element = new XElement("root",int1);

a) Is there a way to specify of which type should element's textual content be and if not, why not?

Thank you

Upvotes: 0

Views: 133

Answers (1)

SLaks
SLaks

Reputation: 887275

No.

XElements store raw, unstructured XML; they have no awareness of the data inside of them.

If you want a strongly-typed API, you should build your own class that wrap or can create XElements.

Upvotes: 1

Related Questions