XML 模式转换
XML Schema transformation
我正在开发一个客户端应用程序(嵌入式系统),它使用 XML 格式与服务器交换数据和配置。
我想在 XML 模式中添加一些额外的信息,关于 XML 数据的处理(例如处理程序或任何自定义操作),而不会对服务器端产生任何副作用。
例如,
<xs:element name="ethernet">
<xs:complexType>
<xs:sequence>
<!-- <handler>set_ethernet_address</handler> -->
<xs:element name="ip" type="ipType"/>
<xs:element name="net_mask" type="ipType"/>
<xs:element name="gateway" type="ipType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
在上面的示例中,注释表示元素 ethernet 具有处理程序 set_ethernet_address。此信息与服务器端用户完全无关。此外,此 handler 元素不是目标 XML 文件的一部分。将来我计划开发一个源代码生成器,它可以从模式中生成客户端应用程序代码。
所以我的问题是,
- 我可以在 XML 模式中添加评论格式以外的额外 "processing instruction" 吗?
- 此外,我能否通过删除特定于客户端的 "processing instruction".
将 XML 架构转换为服务器的新 XML 架构文件
谢谢,
Nandkishor.
推荐的方法是使用 xs:annotation 元素:
<xs:element name="ethernet">
<xs:annotation>
<xs:appInfo source="http://whosebug.com/users/2857369/nandkishor-biradar">
<hander>set_ethernet_address</handler>
</xs:appInfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="ip" type="ipType"/>
<xs:element name="net_mask" type="ipType"/>
<xs:element name="gateway" type="ipType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
我正在开发一个客户端应用程序(嵌入式系统),它使用 XML 格式与服务器交换数据和配置。
我想在 XML 模式中添加一些额外的信息,关于 XML 数据的处理(例如处理程序或任何自定义操作),而不会对服务器端产生任何副作用。
例如,
<xs:element name="ethernet">
<xs:complexType>
<xs:sequence>
<!-- <handler>set_ethernet_address</handler> -->
<xs:element name="ip" type="ipType"/>
<xs:element name="net_mask" type="ipType"/>
<xs:element name="gateway" type="ipType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
在上面的示例中,注释表示元素 ethernet 具有处理程序 set_ethernet_address。此信息与服务器端用户完全无关。此外,此 handler 元素不是目标 XML 文件的一部分。将来我计划开发一个源代码生成器,它可以从模式中生成客户端应用程序代码。
所以我的问题是,
- 我可以在 XML 模式中添加评论格式以外的额外 "processing instruction" 吗?
- 此外,我能否通过删除特定于客户端的 "processing instruction". 将 XML 架构转换为服务器的新 XML 架构文件
谢谢, Nandkishor.
推荐的方法是使用 xs:annotation 元素:
<xs:element name="ethernet">
<xs:annotation>
<xs:appInfo source="http://whosebug.com/users/2857369/nandkishor-biradar">
<hander>set_ethernet_address</handler>
</xs:appInfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="ip" type="ipType"/>
<xs:element name="net_mask" type="ipType"/>
<xs:element name="gateway" type="ipType"/>
</xs:sequence>
</xs:complexType>
</xs:element>