Click to return to the XML (Extensible Markup Language) home page    
Lesson 7     Lesson 9     Lesson List    
Web Workshop  |  XML (Extensible Markup Language)

XML Tutorial
Lesson 8: Accessing Typed XML Values


What is a typed XML value?

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.

Microsoft is providing this release of XML Schema with data type support, as a technology preview that could be useful for developers interested in building prototypes and gaining experience with schema and rich data types. Microsoft is actively involved in defining the emerging W3C XML Schema standard and will track this effort. Developers should note that this version of XML Schema is subject to change.

How do I access typed XML values?

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">
  <date>1970-09-30</date>
  <degrees>67.5</degrees>
</weather>

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"/>
  </ElementType>
</Schema>

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.

Try it!

In the text box below, enter the code that will access the typed value of the date element (assume that "xmlDocument" is the document object), and then click the Check Code button.

To experience the validation capability of data types, see what happens when you enter a date that is not valid. In the text box below, enter an invalid date using the yyyy-mm-dd format. For instance, enter "1998-13-02", and then click the Check Date Validation button.



Back to topBack to top

Did you find this material useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.