2012-02-15 1 views
0

xsdのxsomを使用してxsd要素の最小発生を知りたいのですが、このコードを使って複雑な要素を見つけてください。すべてのxsd element.Atlestの発生を見つけるには、私はあなたが、com.sun.xml.xsomに発生したことを言及していると仮定すると、発生にxsomを使用してxsdの要素のmin-max出現を見つける方法

xmlfile = "Calendar.xsd" 
XSOMParser parser = new XSOMParser(); 

parser.parse(new File(xmlfile)); 
XSSchemaSet sset = parser.getResult(); 
XSSchema s = sset.getSchema(1); 
if (s.getTargetNamespace().equals("")) // this is the ns with all the stuff 
     // in 
{ 
    // try ElementDecls 
    Iterator jtr = s.iterateElementDecls(); 
    while (jtr.hasNext()) 
    { 
    XSElementDecl e = (XSElementDecl) jtr.next(); 
    System.out.print("got ElementDecls " + e.getName()); 
    // ok we've got a CALENDAR.. what next? 
    // not this anyway 
    /* 
    * 
    * XSParticle[] particles = e.asElementDecl() for (final XSParticle p : 
    * particles) { final XSTerm pterm = p.getTerm(); if 
    * (pterm.isElementDecl()) { final XSElementDecl ed = 
    * pterm.asElementDecl(); System.out.println(ed.getName()); } 
    */ 
    } 

    // try all Complex Types in schema 
    Iterator<XSComplexType> ctiter = s.iterateComplexTypes(); 
    while (ctiter.hasNext()) 
    { 
    // this will be a eSTATUS. Lets type and get the extension to 
    // see its a ENUM 
    XSComplexType ct = (XSComplexType) ctiter.next(); 
    String typeName = ct.getName(); 
    System.out.println(typeName + newline); 

    // as Content 
    XSContentType content = ct.getContentType(); 
    // now what? 
    // as Partacle? 
    XSParticle p2 = content.asParticle(); 
    if (null != p2) 
    { 
     System.out.print("We got partical thing !" + newline); 
     // might would be good if we got here but we never do :-(
    } 

    // try complex type Element Decs 
    List<XSElementDecl> el = ct.getElementDecls(); 
    for (XSElementDecl ed : el) 
    { 
     System.out.print("We got ElementDecl !" + ed.getName() + newline); 
     // would be good if we got here but we never do :-(
    } 

    Collection<? extends XSAttributeUse> c = ct.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()); 
    } 
    } 
} 

答えて

1

を見つけるために使用するクラスとメソッドを使用してコードスニペットを与えます(要素は唯一の粒子ではありません)。ここで

はAPIです:maxOccursminOccurs

つのソースについてXSOMを使用してスキーマツリーをトラバースする方法を確認するために見hereを取ってください。基本的に、訪問者パターンがXSOM(Sunがパッケージを作成したもの)でどのように動作するかを示しています。

関連する問題