首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在XSOM Java库中获取Use属性

如何在XSOM Java库中获取Use属性
EN

Stack Overflow用户
提问于 2011-11-29 17:03:48
回答 1查看 1.5K关注 0票数 0

我使用XML库来解析XSOM Schema。我不知道如何为属性声明获取属性"Use“。下面是我为CompleType获取所有属性声明的代码

代码语言:javascript
复制
// 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

指向这条线

代码语言:javascript
复制
XSAttributeDecl attributeDecl = i.next().getDecl();

有人能帮上忙吗?我错过什么了吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2011-11-30 07:05:35

我解决了这个问题谢谢

下面是正确的代码:

代码语言:javascript
复制
// 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());
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8308139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档