父xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SpecialOption">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Option" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
修改xsd之后:添加use =“ required”字段
<xs:element name="SpecialOption">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Option" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
我想将use =“ required”字段添加到父xsd并生成一个新的xsd文件。我想通过Java代码以编程方式执行此操作。
当前,我正在按照以下方法读取xsd文件,但无法找出添加use =“ required”属性的方法How to Programmatically Update and Add Elements to an XSD
非常感谢您的任何帮助。谢谢
使用XSLT。假设XSLT 3.0:
<xsl:transform version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:mode on-no-match="shallow-copy"/> <xsl:template match="xs:element[@name='SpecialOption']//xs:attribute[@name='Option']"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:attribute name="use">required</xsl:attribute> </xsl:copy> </xsl:template> </xsl:transform>
对于较早版本的XSLT并不困难,只是有些冗长。