title: How can I read in XSD elements in complexType? in JAVA
body: <p>XSD schema: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsd:schema targetNamespace="http://www.xxx.sk/sirs"
  elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:sir="http://www.xxx.sk/sirs"&gt;
  
  &lt;xsd:complexType name="Detail_begin"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element name="Block" type="xsd:int"&gt;&lt;/xsd:element&gt;
          &lt;xsd:element name="Select" type="xsd:string"&gt;&lt;/xsd:element&gt;
      &lt;/xsd:sequence&gt;
  &lt;/xsd:complexType&gt;
  
  &lt;xsd:complexType name="MASK"&gt;
      &lt;xsd:sequence&gt;
          &lt;xsd:element name="Number_of_client" type="xsd:int"&gt;&lt;/xsd:element&gt;
          &lt;xsd:element name="Indicator" type="xsd:string"&gt;&lt;/xsd:element&gt;
          &lt;xsd:element name="Domicile" type="xsd:string"&gt;&lt;/xsd:element&gt;
          &lt;xsd:element name="City" type="xsd:string"&gt;&lt;/xsd:element&gt;
          &lt;xsd:element name="Sector" type="xsd:string"&lt;/xsd:element&gt;      
  &lt;/xsd:sequence&gt;
  &lt;/xsd:complexType&gt;
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>I need to read in complexType with name="Detail_begin" and name="MASK" all elements.
  In XSD are more complexTypes.
  Which way is easier? Xpath OR Node or something else?
  I tried this way:</p>
  
  <pre><code>public class XsdRead {
  public static void main(String[] args) {
      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
      Document xmlDocument = null;
      try {
          DocumentBuilder builder =  builderFactory.newDocumentBuilder();
          xmlDocument = builder.parse(new FileInputStream("xml/XmlSchema2.xsd"));
      } catch (Exception e) {
          e.printStackTrace();
      }
      XPath xPath =  XPathFactory.newInstance().newXPath();
      String expression = "//xsd:complexType[@name='Detail_begin' or @name='MASK']//xsd:element";
      NodeList result = null;
      try {
          result = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
      } catch (XPathExpressionException e) {
          e.printStackTrace();
      }
      for (int i = 0; i &lt; result.getLength(); i++) {
          Element el = (Element)result.item(i);
          System.out.println(el.getAttribute("name") + " = " + el.getNodeValue()); 
      }
  }
  }
  </code></pre>
  
  <p>Thanks for advice.</p>