[英]How to get Use Attribute in XSOM Java library
I am using XSOM java library to parse XML Schema. 我正在使用XSOM Java库来解析XML模式。 I don't know how to get the attribute "Use" for the Attribute Declaration.
我不知道如何为属性声明获取属性“ Use”。 Here is my code to get all attribute declarations for the CompleType
这是我的代码,用于获取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());
}
And I get this error: java.util.NoSuchElementException 我收到此错误:java.util.NoSuchElementException
Pointing to the line 指向线
XSAttributeDecl attributeDecl = i.next().getDecl();
Can anyone help? 有人可以帮忙吗? do I miss anything?
我想念什么吗?
Thanks 谢谢
I fixed the problem thanks 我解决了问题,谢谢
the right code here: 正确的代码在这里:
// 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 attUse = i.next();
System.out.println("Attributes for CoplexType:"+ xsComplexType.getName());
parseAttribute(attUse);
}
}
// To Get attribute info
private static void parseAttribute(XSAttributeUse attUse) {
XSAttributeDecl attributeDecl = attUse.getDecl();
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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.