public void testDOMSelector() throws Exception {

    final String markup0 =
        "<!DOCTYPE html>\n<html><body><div><h1>Hello!</h1><p>This is the text over here.</p>"
            + "<p>...and another one!</p></div></body></html>";

    final DOMSelector selector0 = new DOMSelector("//h1");
    final DOMSelector selector1 = new DOMSelector("//p");
    final DOMSelector selector2 = new DOMSelector("/html/p");
    final DOMSelector selector3 = new DOMSelector("/html/body");
    final DOMSelector selector4 = new DOMSelector("/html/body//p");
    final DOMSelector selector5 = new DOMSelector("//body/div/p");

    final Document doc0 = DOMUtils.getHtml5DOMFor(new StringReader(markup0));

    outputResult(selector0, doc0);
    outputResult(selector1, doc0);
    outputResult(selector2, doc0);
    outputResult(selector3, doc0);
    outputResult(selector4, doc0);
    final List<String> list1 = outputResult(selector5, doc0);

    Assert.assertEquals(
        list1,
        (Arrays.asList(
            new String[] {"<p>This is the text over here.</p>", "<p>...and another one!</p>"})));
  }
 public AssignationSequence parseAssignationSequence(
     final Arguments arguments, final String input, final boolean allowParametersWithoutValue) {
   Validate.notNull(arguments, "Arguments cannot be null");
   Validate.notNull(input, "Input cannot be null");
   return parseAssignationSequence(
       arguments, DOMUtils.unescapeXml(input, true), true, allowParametersWithoutValue);
 }
 private static List<String> outputResult(final DOMSelector selector, final Document document) {
   final List<Node> selected = selector.select(document.getChildren());
   final List<String> selectedStrs = new ArrayList<String>();
   for (final Node node : selected) {
     selectedStrs.add(DOMUtils.getHtml5For(node));
   }
   System.out.println("**" + selector + "**");
   for (final String selectedStr : selectedStrs) {
     System.out.println(selectedStr);
   }
   return selectedStrs;
 }
    @Override
    public void startElement(
        final String uri, final String localName, final String qName, final Attributes attributes)
        throws SAXException {

      if (!this.xmlDeclarationComputed) {

        // SAX specification says the "getEncoding()" method in Locator2 can only
        // be called AFTER startDocument has returned and BEFORE endDocument is called.

        if (this.locator != null && this.locator instanceof Locator2) {

          final Locator2 loc = (Locator2) this.locator;

          this.xmlVersion = loc.getXMLVersion();
          this.xmlEncoding = loc.getEncoding();

          // There seems to be no way of obtaining the "standalone" property
          // from the XML declaration.

        }

        this.xmlDeclarationComputed = true;
      }

      flushBuffer();

      Integer lineNumber = null;
      if (this.locator != null) {
        lineNumber = Integer.valueOf(this.locator.getLineNumber());
      }

      final Element element = new Element(qName, this.documentName, lineNumber);

      for (int i = 0; i < attributes.getLength(); i++) {
        element.setAttribute(
            attributes.getQName(i),
            DOMUtils.unescapeXml(
                TemplatePreprocessingReader.removeEntitySubstitutions(attributes.getValue(i)),
                true));
      }

      this.elementStack.push(element);
    }
 public FragmentSelection parseFragmentSelection(final Arguments arguments, final String input) {
   Validate.notNull(arguments, "Arguments cannot be null");
   Validate.notNull(input, "Input cannot be null");
   return parseFragmentSelection(arguments, DOMUtils.unescapeXml(input, true), true);
 }
 public Each parseEach(final Arguments arguments, final String input) {
   Validate.notNull(arguments, "Arguments cannot be null");
   Validate.notNull(input, "Input cannot be null");
   return parseEach(arguments, DOMUtils.unescapeXml(input, true), true);
 }
 public ExpressionSequence parseExpressionSequence(final Arguments arguments, final String input) {
   Validate.notNull(arguments, "Arguments cannot be null");
   Validate.notNull(input, "Input cannot be null");
   return parseExpressionSequence(arguments, DOMUtils.unescapeXml(input, true), true);
 }