假设这个测试 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();
关键是getAttributeWildcard API。