第二十四章 控制到 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/)。
相关推荐
Rockbean29 分钟前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽1 小时前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户60648767188962 小时前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api
只与明月听3 小时前
RAG深入学习之Chunk
前端·人工智能·python
埃博拉酱3 小时前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
用户8356290780514 小时前
自动化文档处理:Python 批量提取 PDF 图片
后端·python
唐宋元明清218818 小时前
.NET 本地Db数据库-技术方案选型
windows·c#
加号320 小时前
windows系统下mysql多源数据库同步部署
数据库·windows·mysql
多恩Stone21 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
tryCbest21 小时前
Windows环境下配置pip镜像源
windows·pip