Package nu.xom

Examples of nu.xom.Node


    }
   
    private static void build(Element parent, NodeFactory factory, Element result) {
      for (int i=0; i < parent.getChildCount(); i++) {
        Nodes nodes;
        Node child = parent.getChild(i);
        if (child instanceof Element) {
          Element elem = (Element) child;
          Element copy = factory.startMakingElement(
              elem.getQualifiedName(), elem.getNamespaceURI());
         
          if (copy != null) {
            result.appendChild(copy);
            result = copy;
            appendNamespaces(elem, result);
            appendAttributes(elem, factory, result);
          }

          build(elem, factory, result); // recurse down
         
          if (copy == null) continue; // skip element
          result = (Element) copy.getParent(); // recurse up
          nodes = factory.finishMakingElement(copy);
          if (nodes.size()==1 && nodes.get(0)==copy) { // same node? (common case)
            continue; // optimization: no need to remove and then readd same element
          }       
          if (result.getChildCount()-1 < 0) {
            throw new XMLException("Factory has tampered with a parent pointer " +
              "of ancestor-or-self in finishMakingElement()");
          }
          result.removeChild(result.getChildCount()-1);       
        } else if (child instanceof Text) {
          nodes = factory.makeText(child.getValue());
        } else if (child instanceof Comment) {
          nodes = factory.makeComment(child.getValue());
        } else if (child instanceof ProcessingInstruction) {
          ProcessingInstruction pi = (ProcessingInstruction) child;
          nodes = factory.makeProcessingInstruction(
            pi.getTarget(), pi.getValue());
        } else {
View Full Code Here


   
    private static void appendNodes(Element elem, Nodes nodes) {
      if (nodes != null) {
        int size = nodes.size();
        for (int i=0; i < size; i++) {
          Node node = nodes.get(i);
          if (node instanceof Attribute) {
            elem.addAttribute((Attribute) node);
          } else {
            elem.insertChild(node, elem.getChildCount());
          }
View Full Code Here

     *            the subtree to normalize
     */
    public final void normalize(ParentNode node) {
      // rather efficient implementation
      for (int i=node.getChildCount(); --i >= 0; ) {
        Node child = node.getChild(i);
        if (child instanceof Element) { // recursively walk the tree
          normalize((Element)child);
        }
        else if (child instanceof Text) {
          // scan to beginning of adjacent run, if any
          int j = i;
          while (--i >= 0 && node.getChild(i) instanceof Text) ;
         
          i++;
          if (j != i) { // > 1 adjacent Text nodes (rare case)
            merge(node, i, j); // merge into a single Text node
          } else { // found isolated Text node (common case)
            String value = child.getValue();
            String norm = normalizeWhitespace(value);
            if (norm.length() == 0) {
              node.removeChild(i);
            } else if (!norm.equals(value)) {
              ((Text) child).setValue(norm);
View Full Code Here

     
      writeXMLDeclaration();
     
      int size = nodes.size();
      for (int i=0; i < size; i++) {
        Node node = nodes.get(i);
        if (node instanceof Attribute) {
          throw new XMLException(
          "SENR0001: W3C XQuery Serialization spec forbids top-level attributes");
//        } else if (node instanceof Namespace) {
//          throw new XMLException(
//          "SENR0001: W3C XQuery Serialization spec forbids top-level namespaces");
        } else if (node instanceof Document) {
          // Replace document with its children
          // Note that a Document can't have an atomic value or Text as child
          Document doc = (Document) node;
          for (int j=0; j < doc.getChildCount(); j++) {
            Node child = doc.getChild(j);
            if (mayBreakLine && indentYes && child instanceof Element) {
              breakLine();
            }
            writeChild(child);
            mayBreakLine = true;
View Full Code Here

         
          if (check && results != null) { // found the right results?
            for (int j=0; j < results.size(); j++) {
              System.out.println("node " + j + ": " + results.get(j).toXML());
            }
            Node first = results.size() == 0 ? null : results.get(0)
            Object actual = null;
            switch (types[i]) {
              case 0 : actual = String.valueOf(results.size()); break;
              case 1 : actual = first == null ? "" : first.getValue(); break;
              case 2 : actual = first == null ? "0.0" : new Double(first.getValue()).toString(); break;
              case 3 : actual = first == null ? "false" : first.getValue().equals("true") ? "true" : "false"; break;
              default: throw new IllegalStateException();
            }       
            if (expected[i] instanceof String && ((String)expected[i]).length() > 0 && !expected[i].equals(actual)) {
              System.out.print("expected="+expected[i]);
              System.out.println(", actual="+actual);
View Full Code Here

      Attribute a = elem.getAttribute(i);
      makeAttribute(a.getQualifiedName(), a.getNamespaceURI(),
          a.getValue(), a.getType());
    }
    for (int i=0; i < elem.getChildCount(); i++) {
      Node node = elem.getChild(i);
      if (node instanceof Element) {
        collect((Element) node); // recurse
      }
    }
   
View Full Code Here

    if (value == null) value = elem.getAttributeValue("instances");
    incrementValue(elem, "descendants-or-self-percent",
        (int) Math.round(100.0 * Integer.parseInt(value) / total));
   
    for (int i=0; i < elem.getChildCount(); i++) {
      Node node = elem.getChild(i);
      if (node instanceof Element) {
        addAccumulatedPercentages((Element)node, total); // recurse
      }
    }
  }
View Full Code Here

 
  private static void appendNodesToElement(Element elem, Nodes nodes) {
    if (nodes != null) {
      int size = nodes.size();
      for (int i=0; i < size; i++) {
        Node node = nodes.get(i);
        if (node instanceof Attribute) {
          elem.addAttribute((Attribute) node);
        } else {
          elem.insertChild(node, elem.getChildCount());
        }
View Full Code Here

 
  private void appendNodesToDocument(Document doc, Nodes nodes, int k) {
    if (nodes != null) {
      int size = nodes.size();
      for (int i=0; i < size; i++) {
        Node node = nodes.get(i);
        if (node instanceof Element) {
          if (hasRootElement[k]) {
            throw new IllegalAddException(
              "Factory returned multiple root elements");
          }
View Full Code Here

 
  private void buildIDIndex(Element elem) {
    // walk the tree in reverse document order, to satisfy the XPath 1.0 rule
    // that says if an ID appears twice, the first one wins
    for (int i=elem.getChildCount(); --i >= 0 ; ) {
      Node child = elem.getChild(i);
      if (child instanceof Element) {
        buildIDIndex((Element)child);
      }
    }
    for (int i=elem.getAttributeCount(); --i >= 0 ; ) {
View Full Code Here

TOP

Related Classes of nu.xom.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.