Main Content

matlab.io.xml.dom.TypeInfo Class

Namespace: matlab.io.xml.dom

Schema type information

Since R2021a

Description

An object of the matlab.io.xml.dom.TypeInfo class specifies the name, namespace, and derivation of an element or attribute type that is defined by a schema.

The matlab.io.xml.dom.TypeInfo class is a handle class.

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

To create a matlab.io.xml.dom.TypeInfo object, call the getSchemaTypeInfo method of a matlab.io.xml.dom.Element or matlab.io.xml.dom.Attr object contained in a parsed matlab.io.xml.dom.Document object. The type information is available in an element or attribute only if you configure the parser to validate the XML against a schema and save the post-schema-validation information (PSVI) in the elements and attributes.

Properties

expand all

Name of this schema type, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Namespace of this schema type, specified as a character vector.

Attributes:

GetAccess
public
SetAccess
immutable
NonCopyable
true
Transient
true

Methods

expand all

Examples

collapse all

This example saves post-schema-validation information (PSVI) in the elements of a parsed XML document and then uses a matlab.io.xml.dom.TypeInfo object to get the type of one of the elements.

The file checkingaccount.xml contains the markup for a bank account and specifies the schema checkingaccount.xsd.

type checkingaccount.xml
<?xml version="1.0" encoding="UTF-8"?>

<account
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="checkingaccount.xsd">
  <id>12345678</id>
  <name>Jane Jones</name>
  <balance>1000.00</balance>
</account>

The schema specifies that an account element has an id, name, and balance element. The id and name elements must contain a string and the balance element must contain a decimal number.

type checkingaccount.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="account">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="id" type="xs:string"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="balance" type="xs:decimal"/>
    </xs:sequence>
   </xs:complexType>
</xs:element>

</xs:schema>

Configure a parser to validate the XML against the schema and save the post-schema-validation information in the parsed elements. Read the XML file into a DOM document using the parser.

import matlab.io.xml.dom.*

parser = Parser();
parser.Configuration.Schema = true;
parser.Configuration.Validate = true;
parser.Configuration.HasPSVI = true;
doc = parseFile(parser,"checkingaccount.xml");

Find the balance element in the document.

nodelistObj = getElementsByTagName(doc,"balance");
balanceElementObj = node(nodelistObj,1);

Return the type information for the balance element as a matlab.io.xml.dom.TypeInfo object.

typeInfoObj = getSchemaTypeInfo(balanceElementObj);

To get the name of the type, call the getTypeName method.

getTypeName(typeInfoObj)
ans = 
'decimal'

Version History

Introduced in R2021a