第二十四章 控制到 XML 模式的映射

文章目录

第二十四章 控制到 XML 模式的映射

对于任何支持XML的类,都有一个用于该类的隐式XML模式,可以查看它。 IRIS 提供了修改该模式的方法。

本主题中的XML示例采用文字格式。

类和属性参数

  • CONTENT
  • DISPLAYLIST
  • VALUELIST
  • ESCAPE
  • MAXLEN
  • MINLEN
  • MINVAL
  • XMLFractionDigits
  • XMLTotalDigits
  • XMLLISTPARAMETER
  • XSDTYPE
  • XMLTYPE
  • SUPPRESSTYPEPREFIX

查看支持xml的类的模式

要查看给定支持xml的类的模式,有两个选项:

可以使用 %XML.Schema%XML.Writer 生成完整的架构文档。

可以使用支持 XML 的类的 XMLSchema() 类方法,该方法将该类的 XML 架构写入当前设备。此方法不编写 XML 声明并忽略名称空间,因此用途有限。但是,如果只对 XML 类型感兴趣,则此方法可能会很有帮助。

java 复制代码
Class GXML.Person Extends (%Persistent, %Populate, %XML.Adaptor) 
{
Property Name As %Name;
Property DOB As %Date(FORMAT = 5, MAXVAL = "+$h");
Property GroupID As %String (XMLPROJECTION="ATTRIBUTE");
Property OtherID As %String(XMLPROJECTION = "NONE");
Property Address As GXML.Address;
Property Doctors As list Of GXML.Doctor;
}

GXML.Address 类如下:

java 复制代码
Class GXML.Address Extends (%Persistent, %Populate, %XML.Adaptor) 
{
Property Street As %String;
Property City As %String;
Property State As %String(MAXLEN = 2, PATTERN = "2u");
Property Zip As %String(MAXLEN = 10, PATTERN = "5n.1(1""-""4n)");
}

GXML.Doctor类如下:

java 复制代码
Class GXML.Doctor Extends (%Persistent, %Populate, %XML.Adaptor) 
{
Property Name As %Name;
}

要查看 GXML.Person 类的架构,请在终端中输入以下命令:

java 复制代码
 do ##class(GXML.Person).XMLSchema()

然后会看到以下内容:

xml 复制代码
<s:complexType name="Person">
    <s:sequence>
        <s:element name="Name" type="s:string" minOccurs="0" />
        <s:element name="DOB" type="s:date" minOccurs="0" />
        <s:element name="Address" type="s_Address" minOccurs="0" />
        <s:element name="Doctors" type="ArrayOfDoctorDoctor" minOccurs="0" />
    </s:sequence>
    <s:attribute name="GroupID" type="s:string" />
</s:complexType>
<s:complexType name="s_Address">
    <s:sequence>
        <s:element name="City" type="s:string" minOccurs="0" />
        <s:element name="Zip" type="s:string" minOccurs="0" />
    </s:sequence>
</s:complexType>
<s:complexType name="ArrayOfDoctorDoctor">
    <s:sequence>
        <s:element name="Doctor" type="Doctor" 
minOccurs="0" maxOccurs="unbounded" nillable="true" />
    </s:sequence>
</s:complexType>
<s:complexType name="Doctor">
    <s:sequence>
        <s:element name="Name" type="s:string" minOccurs="0" />
    </s:sequence>
</s:complexType>

请注意以下事项:

  • <Person>, <Address>, 和 <Doctor> 类型的架构直接基于相应的类定义。
  • 该架构仅包含映射的属性。
  • 该模式识别每个属性是否被映射为元素或属性。例如,GroupID 是一个属性,Name 是一个元素。
  • 属性的其他参数可能会影响架构。
  • 在此示例中,类属性的类型为 string,它是基本 XSD 类型之一(请参阅 https://www.w3.org/TR/xmlschema-2/)。
相关推荐
reasonsummer4 小时前
【办公类-100-01】20250515手机导出教学照片,自动上传csdn+最大化、最小化Vs界面
开发语言·python
Doker 多克5 小时前
Python-Django系列—日志
python·日志
苏三福6 小时前
ros2 hunmle bag 数据包转为图片数据 python版
开发语言·python·ros2humble
大神薯条老师7 小时前
Python零基础入门到高手8.4节: 元组与列表的区别
开发语言·爬虫·python·深度学习·机器学习·数据分析
z人间防沉迷k7 小时前
堆(Heap)
开发语言·数据结构·笔记·python·算法
小白学大数据7 小时前
Python爬虫如何应对网站的反爬加密策略?
开发语言·爬虫·python
Eric.Lee20217 小时前
Ubuntu shell指定conda的python环境启动脚本
python·ubuntu·conda·shell
芒果量化8 小时前
量化交易 - 网格交易策略实现与原理解析
python·算法·机器学习·金融
LetsonH8 小时前
Python工具链UV整合环境管理
开发语言·python·uv
欣然~8 小时前
基于深度学习进行运输系统优化
python·深度学习