matlab.io.xml.dom.TypeInfo 类
包: matlab.io.xml.dom
说明
matlab.io.xml.dom.TypeInfo
类的一个对象指定由架构定义的元素或属性类型的名称、命名空间和派生。
matlab.io.xml.dom.TypeInfo
类是 handle
类。
创建对象
要创建 matlab.io.xml.dom.TypeInfo
对象,请调用已解析的 matlab.io.xml.dom.Document
对象中包含的 matlab.io.xml.dom.Element
或 matlab.io.xml.dom.Attr
对象的 getSchemaTypeInfo
方法。仅当您将解析器配置为根据架构验证 XML 并将架构验证后信息 (PSVI) 保存在元素和属性中时,元素或属性中的类型信息才可用。
属性
TypeName
— 架构类型的名称
字符向量
此架构类型的名称,指定为字符向量。
属性:
GetAccess | public |
SetAccess | immutable |
NonCopyable | true |
Transient | true |
TypeNamespace
— 架构类型的命名空间
字符向量
此架构类型的命名空间,指定为字符向量。
属性:
GetAccess | public |
SetAccess | immutable |
NonCopyable | true |
Transient | true |
方法
公共方法
getTypeName |
|
getTypeNameSpace |
|
isDerivedFrom | 如果具有指定的命名空间和名称的另一个架构类型是通过指定的派生方法从此类型派生的,则 将
|
示例
获取已解析的 XML 文档中元素的类型
此示例将架构验证后信息 (PSVI) 保存在已解析的 XML 文档的元素中,然后使用 matlab.io.xml.dom.TypeInfo
对象来获取其中一个元素的类型。
文件 checkingaccount.xml
包含银行帐户的标记,并指定架构 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>
该架构指定 account
元素具有 id
、name
和 balance
元素。id
和 name
元素必须包含字符串,balance
元素必须包含十进制数字。
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>
将一个解析器配置为根据架构验证 XML,并将架构验证后信息保存在解析后的元素中。使用该解析器将 XML 文件读入 DOM 文档中。
import matlab.io.xml.dom.* parser = Parser(); parser.Configuration.Schema = true; parser.Configuration.Validate = true; parser.Configuration.HasPSVI = true; doc = parseFile(parser,"checkingaccount.xml");
在该文档中找到 balance
元素。
nodelistObj = getElementsByTagName(doc,"balance");
balanceElementObj = node(nodelistObj,1);
以 matlab.io.xml.dom.TypeInfo
对象形式返回 balance
元素的类型信息。
typeInfoObj = getSchemaTypeInfo(balanceElementObj);
要获取类型的名称,请调用 getTypeName
方法。
getTypeName(typeInfoObj)
ans = 'decimal'
版本历史记录
在 R2021a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)