第二十四章 控制到 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/)。
相关推荐
M--Y9 小时前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
岁月宁静9 小时前
DeepSeek Harness 实战与架构解析:让 Agent 从“会聊”到“能交付”
人工智能·python·agent
LiaoWL1239 小时前
NumPy 入门实战(二):向量化与余弦相似度——从 ndarray 到 Embedding
python·numpy·embedding
forest_0910 小时前
多 Agent 协作第二课:交叉验证≠独立验证
人工智能·python·算法·机器学习·prompt·agi
databook13 小时前
时间序列数据,先拆规律还是先查异常
python·数据挖掘·数据分析
师夷长技以自愈13 小时前
手搓 AI Agent 第 8 篇:从手写循环到画流程图——LangGraph 封装
人工智能·python
aifannihao14 小时前
Rust 1.100 的 DropGuard:用 Python 实测失败回滚与吞异常
python·rust·异常处理·标准库·contextlib
用户0190275816116 小时前
天勤 tqsdk 能做 A 股行情吗?期货强项与股票数据选型
python
2601_9679791217 小时前
pip在Python中的9个必须知道的用法
python·pip·版本控制·包管理工具·requirements.txt
Funlang18 小时前
在 Windows 95 上跑 Fun
windows