有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

XSD XSOM:如何使用XSOM Java库解析xs:anyAttribute?

我正在尝试解析此复杂类型,但无法获取<;xsd:anyAttribute元素使用XSOM JAVA。 我尝试过getAttributeUse()和particle,但无法获得它

你知道如何解析它吗

      <xsd:sequence>

      <xsd:any namespace="##other" processContents="lax" maxOccurs="unbounded"/>

      </xsd:sequence>

      <xsd:anyAttribute namespace="##other" processContents="lax"/>


共 (1) 个答案

  1. # 1 楼答案

    假设此测试为XSD:

    <?xml version="1.0" encoding="utf-8" ?>
    <! XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com) >
    <xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:complexType name="test">
            <xsd:sequence>
                <xsd:any namespace="##other" processContents="lax" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:anyAttribute namespace="##other" processContents="lax"/>
        </xsd:complexType>
    </xsd:schema>
    

    您需要以下代码:

        XSOMParser parser = new XSOMParser();
        //parser.setErrorHandler(...);
        //parser.setEntityResolver(...);
    
        parser.parse(new File(...));
    
        XSSchemaSet sset = parser.getResult();
        XSComplexType xt = sset.getComplexType("http://tempuri.org/XMLSchema.xsd", "test");
        XSWildcard anyAttr = xt.getAttributeWildcard();
    

    关键是getAttributeWildcardAPI