将 XML 从旧模式转换为新模式?
我需要将不使用任何模式的 XML 文档转换为使用定义良好的模式的另一种格式。
所以基本上我必须将其转换为:
<healthCareFacilityTypeCode
displayName="Home"
codingScheme="Connect-a-thon healthcareFacilityTypeCodes"
>Home</healthCareFacilityTypeCode>
转换为:
<healthCareFacilityTypeCode>
<code>Home</code>
<displayName>
<LocalizedString value="Home" />
</displayName>
<schemeName>Connect-a-thon healthcareFacilityTypeCodes</schemeName>
</healthCareFacilityTypeCode>
我知道如何通过查看模式来手动转换它。以下是 XSD 的片段:
<xsd:complexType name="DocumentEntryType">
<xsd:sequence>
<xsd:element minOccurs="0"
name="healthCareFacilityTypeCode"
type="tns:CodedMetadataType"/>
</xsd:sequence>
<xsd:attribute default="false"
name="existing"
type="xsd:boolean"
use="optional"/>
</xsd:complexType>
<xsd:element name="DocumentEntry" type="tns:DocumentEntryType"/>
我不知道如何解决的是:如何利用目标 XSD 将节点从源 XML 转换为目标 XML 文档。我觉得执行转换的所有信息都位于 XSD 中,但我可以使用它吗?如何?
I need to transform an XML document which does not use any schema to another format which uses a well defined schema.
So basically I have to transform this:
<healthCareFacilityTypeCode
displayName="Home"
codingScheme="Connect-a-thon healthcareFacilityTypeCodes"
>Home</healthCareFacilityTypeCode>
Into this:
<healthCareFacilityTypeCode>
<code>Home</code>
<displayName>
<LocalizedString value="Home" />
</displayName>
<schemeName>Connect-a-thon healthcareFacilityTypeCodes</schemeName>
</healthCareFacilityTypeCode>
I know how to transform it by hand by looking at the schema. Here is a snippet of the XSD:
<xsd:complexType name="DocumentEntryType">
<xsd:sequence>
<xsd:element minOccurs="0"
name="healthCareFacilityTypeCode"
type="tns:CodedMetadataType"/>
</xsd:sequence>
<xsd:attribute default="false"
name="existing"
type="xsd:boolean"
use="optional"/>
</xsd:complexType>
<xsd:element name="DocumentEntry" type="tns:DocumentEntryType"/>
What I don't know how to tackle is: how to exploit the target XSD to transform a node from the source XML to the target XML doc. I feel all the info to perform the transform is located in the XSD but can I use it? how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遵循建议,这就是我想出的。虽然不完美,但足以满足我的目的。
Followed suggestions and this is what I came up with. Not perfect but it is enough for my purpose.