Access Typed XML Values


This topic discusses typed XML values.

A typed XML value is an XML element value that has been assigned a data type in an XML Schema, a formal definition of an XML document. The XML parser uses the schema to validate the document. The XML Schema information resides either in a schema file or within the XML document itself.

It is possible to access typed data through the XML object model. Just as you can retrieve the value of an element by calling the nodeValue property on that element's node, you can retrieve the typed value of an element by calling the nodeTypedValue property on the element itself.

For example, consider the following XML document:

<?xml version="1.0"?>
<weather xmlns="x-schema:weatherSchema.xml">

where weatherSchema.xml is the following file:

<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <ElementType name="date" content="textOnly" dt:type="date"/>
  <ElementType name="degrees" content="textOnly" dt:type="float"/>
  <ElementType name="weather" content="eltOnly">
    <element type="date"/>
    <element type="degrees"/>

If you navigate to the <degrees> element (xmlDocument.documentElement.childNodes.item(1)), you can access its typed value by calling nodeTypedValue, as follows: xmlDocument.documentElement.childNodes.item(1).nodeTypedValue