从元素中使用XSOM获取minOccurs属性 [英] getting the minOccurs attribute using XSOM from an element

查看:321
本文介绍了从元素中使用XSOM获取minOccurs属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用XSOM解析器从元素中获取minOccurs属性?我已经看到这个示例获取与复杂类型相关的属性:

How do I get the minOccurs attribute off of an element using the XSOM parser? I've seen this example for getting the attributes related to a complex type:

private void getAttributes(XSComplexType xsComplexType){
    Collection<? extends XSAttributeUse> c = xsComplexType.getAttributeUses();
    Iterator<? extends XSAttributeUse> i = c.iterator();while(i.hasNext()){
        XSAttributeDecl attributeDecl = i.next().getDecl();
        System.out.println("type: "+attributeDecl.getType());
        System.out.println("name:"+attributeDecl.getName());
    }
}

但似乎无法弄清楚从以下元素中取出它的方法:

But, can't seem to figure out the right way for getting it off an an element such as:

<xs:element name="StartDate" type="CommonDateType" minOccurs="0"/>

谢谢!

推荐答案

所以这不是那么直观,但XSElementDecl来自XSParticles。我能够使用以下代码检索相应的属性:

So this isn't really that intuitive, but the XSElementDecl come from XSParticles. I was able to retrieve the corresponding attribute with the following code:

public boolean isOptional(final String elementName) {
    for (final Entry<String, XSComplexType> entry : getComplexTypes().entrySet()) {
        final XSContentType content = entry.getValue().getContentType();
        final XSParticle particle = content.asParticle();
        if (null != particle) {
            final XSTerm term = particle.getTerm();
            if (term.isModelGroup()) {
                final XSParticle[] particles = term.asModelGroup().getChildren();
                for (final XSParticle p : particles) {
                    final XSTerm pterm = p.getTerm();
                    if (pterm.isElementDecl()) {
                        final XSElementDecl e = pterm.asElementDecl();
                        if (0 == e.getName().compareToIgnoreCase(elementName)) {
                            return p.getMinOccurs() == 0;
                        }
                    }
                }
             }
          }
    }
    return true;
}

这篇关于从元素中使用XSOM获取minOccurs属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆