我正在使用XSOM java 库来解析 XML Schema。我不知道如何获取属性声明的属性“使用”。这是我获取 CompleType 的所有属性声明的代码
// To get ComplexType attributes
private static void getComplexAttributes(XSComplexType xsComplexType) {
Collection<? extends XSAttributeUse> c = xsComplexType.getAttributeUses();
Iterator<? extends XSAttributeUse> i = c.iterator();
while(i.hasNext()) {
// i.next is attributeUse
XSAttributeUse attributeUse = i.next();
XSAttributeDecl attributeDecl = i.next().getDecl();
System.out.println("Attributes for CoplexType: " + xsComplexType.getName());
parseAttribute(attributeDecl, attributeUse);
}
}
// Get attribute info
private static void parseAttribute(XSAttributeDecl attributeDecl, XSAttributeUse attUse) {
System.out.println("Attribute Name: " + attributeDecl.getName());
XSSimpleType xsAttributeType = attributeDecl.getType();
System.out.println("Attribute Type: " + xsAttributeType.getName());
if (attUse.isRequired())
System.out.println("Use: Required");
else
System.out.println("Use: Optional");
System.out.println("Fixed: " + attributeDecl.getFixedValue());
System.out.println("Default: " + attributeDecl.getDefaultValue());
}
我得到这个错误:java.util.NoSuchElementException
指向线
XSAttributeDecl attributeDecl = i.next().getDecl();
任何人都可以帮忙吗?我想念什么吗?
谢谢