2014-03-05 3 views
-1

XmlSchemaElement에서 바인딩되지 않은 모든 요소를 ​​어떻게 찾을 수 있습니까? 나는 다음과 같이 아파치의 WS 라이브러리 ... 요소,XmlSchemaElement의 모든 바인딩되지 않은 요소 찾기

<xs:complexType> 

     <xs:sequence maxOccurs="unbounded" > 

      <xs:element 
       name="“Object123" 
       type="“ObjectType" > 

       <xs:annotation> 

        <xs:appinfo> 

         <xs:attribute 
          name="“ObjectLabel" 
          default="“Object" /> 
        </xs:appinfo> 
       </xs:annotation> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 

답변

0

그래서이 내가 찾던 나는 마침내 그것을 발견,

http://www.docjar.com/html/api/org/apache/ws/commons/schema/SchemaBuilder.java.html

그래서 따라 무엇인가 그걸로, 그냥 엄마가 걸립니다. x의 용량을 계산 한 다음 요소의 최대 제한되지 않은 용량으로 사용합니다.

XmlSchemaSequence sequence = (XmlSchemaSequence) childParticle; 
if(sequence.getMaxOccurs() == Long.MAX_VALUE){ 
    //unbounded element 
} 
0

XML 스키마 문서는 유효한 XML 문서입니다을 사용하고 있습니다.

import javax.xml.xpath.XPath; 
import javax.xml.xpath.XPathFactory; 

// ... load your schema into xmlDocument and then do the following: 

XPath xPath = XPathFactory.newInstance().newXPath(); 
String expression = "//*[@maxOccurs='unbounded']"; 
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); 

// nodeList contains what you're looking for. 
0

당신이 이것을 달성하기 위해 XmlPullParser 클래스의 인스턴스를 사용할 수 있습니다 : 당신이 다른 XML 파일과 함께 사용하면 마찬가지로로드 및 자바 maxOccurs="unbounded" 예와 요소를 검색하는 XPath를 사용하는 것이 좋습니다.

public class UnboundItems { 
    private String name; 
    private String type; 
    // Whatever else you need... 

    public getName() { return name; } 
    public getType() { return type; } 
    public setName(String _name) { name = _name; } 
    public setType(String _type) { type = _type; } 
}  

private void parseXML(final XmlPullParser parser) throws XmlPullParserException, IOException { 
    int eventType; 
    ArrayList<UnboundItems> unbItems; 

    while ((eventType = parser.getEventType()) != XmlPullParser.END_DOCUMENT) { 
    UnboundItems currentUnboundItem; // For current iteration 
    boolean processing_unbound = false; 
    String curtag = null;    // The current tag 
    switch (eventType) { 
     case XmlPullParser.START_DOCUMENT: 
     break; 

     case XmlPullParser.START_TAG: 
     curtag = parser.getName();    // Get the current tag's name 
     if (curtag.equals("xs:complexType")) 
      ... 
     else if (curtag.equals("sequence")) { // The unbound items will be under this tag 
      currentUnboundItem = new UnboundItems(); 
      processing_unbound = true; 
     } 
     else if ((curtag.equals("element")) && (processing_unbound)) { 
      // Get attribute values 
      final String name = parser.getAttributeValue(null, "name"); 
      final String type = parser.getAttributeValue(null, "type"); 
      currentUnboundItem.setName(name); 
      currentUnboundItem.setType(type); 
      ... 
     } 
     } 

     break; 

    case XmlPullParser.END_TAG: 
     curtag = parser.getName(); 
     if ((curtag.equals("xs:complexType")) && (processing_unbound)) { 
     // Probably add the UnboundItem to your array here 
     unbItems.add(currentUnboundItem); 
     ... 
     processing_unbound = false; 
     } 

     break; 
    } 

    eventType = parser.next();     // Next event 
    } 
} 

사용자가 볼 수 있듯이 필요한만큼 복잡하게 만들 수 있습니다. 이 XML 문서는 이러한 방식으로 처리 될 수 있기 때문에 얼마나 복잡한 지와 요구 사항을 사용자에게 달려 있습니다. 일부 유용한 링크 :

+1

실제로 아파치의 ws xml 파서를 사용하는 이유는 모르지만 ... 나는 노력에 대한 현상금을 줄 것이다 ... – Hades

관련 문제