我正在使用 Apache Xerces 来解析 xml,由于某些原因,我需要查找元素在 xsd 中定义了多少个属性。 element.getAttributes 只是给我所有存在的属性。有什么想法吗?
最佳答案
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
XSModel xsModel = schemaLoader.loadURI(xsdResource.getURL().getPath());
((XSComplexTypeDecl) xsModel.getComponents(XSTypeDefinition.COMPLEX_TYPE).itemByName(xsdName, "typeName")).getAttrGrp().getAttributeUses();
关于java - 获取 xml 模式中定义的元素属性的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16581434/