code: public Xml read(String xmlPathQuery, boolean captureContent) {
          XmlPath xmlPath = XmlPathParser.parse(xmlPathQuery);
          Xml doc = new Xml();
          boolean record = false;
          int levelIndex = 0;
  
          XmlNode node;
          while((node = pullXmlNode()) != null) {
              if(node instanceof XmlStartElement) {
                  XmlStartElement startElement = (XmlStartElement) node;
                  Element element = new Element(startElement.getLocalName());
                  element.addAttributes(startElement.getAttributes());
                  currentPath.addLast(element);
                  if(xmlPath.matches(currentPath)) {
                      if(!captureContent) {
                          // capture single element only
                          doc.addElement(element);
                          return doc;
                      }
                      // turn on document builder
                      record = true;
                  }
                  if(record) {
                      // build document
                      doc.addElement(element);
                      levelIndex += 1;
                  }
              } else if(node instanceof XmlEndElement) {
                  if(xmlPath.isSimplePattern() && levelIndex == 0) {
                      // a simple pattern query can not read further up
                      nodeQueue.push(node);
                      return null;
                  }
                  if(currentPath.getLast() instanceof Content) {
                      currentPath.removeLast();
                  }
                  currentPath.removeLast();
                  if(record) {
                      // build document
                      doc.endElement();
                      levelIndex -= 1;
                      if(levelIndex == 0) {
                          return doc;
                      }
                  }
              } else if(node instanceof XmlContent) {
                  XmlContent content = (XmlContent) node;
                  if(currentPath.getLast() instanceof Content) {
                      currentPath.removeLast();
                  }
                  currentPath.addLast(new Content(content.getText()));
                  if(record) {
                      // build document
                      doc.addContent(new Content(content.getText()));
                  }
              } else {
                  // don't know how to handle this type, internal error
                  throw new XmlReaderException("Unknown XmlNode type: " + node);
              }
          }
          // no element was found matching the query
          return null;
      }
docs: Read an XML {@code Xml} object from the input stream
  @param xmlPathQuery XML path query
  @param captureContent capture child content
  @return {@code Xml}