Package nu.xom

Examples of nu.xom.Node


    // assert: we are currently positioned *before* the first event, with the
    // behaviour of all methods initially undefined, except for reader.hasNext()
    try {
      Nodes results = new Nodes();
      while (reader.hasNext()) {
        Node node;
        switch (reader.next()) {
          case XMLStreamConstants.START_DOCUMENT:
            node = build(); // FIXME don't auto-close reader?
            break;
          case XMLStreamConstants.START_ELEMENT:
View Full Code Here


     * It is recommended (but not strictly necessary) that parameter
     * <code>nodes</code> does not contain duplicates wrt. node identity.
     */
    HashSet identities = null;
    for (int i=nodes.size(); --i >= 0; ) {
      Node node = nodes.get(i);
      Nodes results = EMPTY;
      if (morpher != null) {
        try {
          results = morpher.execute(node, null, variables).toNodes();
        } catch (XQueryException e) { // part of the "convenience"
          throw new RuntimeException(e);
        }
      }
     
      int size = results.size();
      if (size == 0) { // pure delete?
        node.detach();
        continue; // not really needed; just for clarity
      }
     
      if (size == 1 && node == results.get(0)) {
        continue; // nothing to do (replace X with X)
      }

      ParentNode parent = node.getParent();
      StringBuffer atomics = null;
      boolean isInitialized = false;
      int position = 0;
      if (size > 1) {
        if (identities == null) {
          identities = new HashSet();
        } else {
          identities.clear();
        }
      }
     
      for (int j=0; j < size; j++) {
        Node result = results.get(j);       
        if (DefaultResultSequence.isAtomicValue(result)) { // concat atomic values
          String value = result.getValue();
          if (atomics == null) {
            atomics = new StringBuffer(value.length());
          } else {
            atomics.append(' ');
          }
          atomics.append(value);
        } else if (parent != null) {
          if (size > 1 && !identities.add(result)) {
            result = result.copy(); // multiple identical nodes in results
//            throw new MultipleParentException(
//            "XQuery morpher result sequence must not contain multiple identical nodes");
          }
          boolean isRoot = parent instanceof Document && node instanceof Element;
          if (!isInitialized) {
            if (!(node instanceof Attribute)) position = parent.indexOf(node);
            if (!isRoot) node.detach();
            isInitialized = true;
          }
         
          if (result instanceof Attribute) {
            result.detach();
            ((Element) parent).addAttribute((Attribute)result);
          } else {
            if (isRoot && result instanceof Element) {
              parent.replaceChild(node, result);
            } else {
              result.detach();
              parent.insertChild(result, position);
            }
            position++;
          }
        }
View Full Code Here

      if (transform == null) return super.finishMakingElement(elem);
      Nodes results = transform.transform(elem);

      // prevent potential nu.xom.MultipleParentException by detaching
      for (int i = results.size(); --i >= 0; ) {
        Node node = results.get(i);
        if (node != elem) node.detach();
      }
      return results;
    }
View Full Code Here

    this.config = config;
  }
 
  public Nodes toNodes() throws XQueryException {
    Nodes nodes = new Nodes();
    Node next;
    while ((next = next()) != null) {
      nodes.append(next);
    }
    return nodes;
  }
View Full Code Here

  /** Converts a saxon result node coming from XQuery node constructors to XOM. */
  private Node convertTree(NodeInfo node) {
    if (PRESERVE_IDENTITIES && this.alreadyConverted == null) {
      this.alreadyConverted = new HashMap();
    }
    Node value = convertNodeInfo(node);
    if (PRESERVE_IDENTITIES && node.getNodeKind() != Type.NAMESPACE) {
      NodeInfo root = node.getRoot();
      if (!root.isSameNodeInfo(node)) {
        if (DEBUG) System.err.println(
            "ROOT converting nodeinfo: " + root.getStringValue() + " : " + root);
View Full Code Here

    return value;
  }
 
  /** Converts a saxon result node coming from XQuery node constructors to XOM. */
  private Node convertNodeInfo(NodeInfo node) {
    Node value;
    Object key = null;
    if (PRESERVE_IDENTITIES) {
      // if the node has already been converted return the previous conversion result.
      if (saxon86GenerateIdMethod == null) {
        key = node; // saxon >= 8.7
View Full Code Here

    boolean hasRootElement = false;
    int i = 0;
    NodeInfo next;
    AxisIterator iter = node.iterateAxis(Axis.CHILD);
    while ((next = (NodeInfo) iter.next()) != null) {
      Node child = convertNodeInfo(next);
      if (child instanceof Element) { // replace fake root with real root
        if (hasRootElement) throw new IllegalAddException(
          "A XOM document must not have more than one root element.");
        doc.setRootElement((Element) child);
        hasRootElement = true;
View Full Code Here

      XQueryUtil.xquery(catalog, ns + "ns:test-suite/@XQueryQueryOffsetPath").get(0).getValue());
    File testSourcesDir = new File(rootDir, "TestSources");   
    Nodes testCases = XQueryUtil.xquery(catalog, ns + "//ns:test-case");
   
    for (int i=0; i < testCases.size(); i++) {
      Node testCase = testCases.get(i);

//      String groupTitle = XQueryUtil.xquery(testCase, ns + "../ns:GroupInfo/ns:title").get(0).getValue();
      String path = XQueryUtil.xquery(testCase, "@FilePath").get(0).getValue();
      File query = new File(new File(queryDir, path),
        XQueryUtil.xquery(testCase, ns + "ns:query/@name").get(0).getValue() + ".xq");
View Full Code Here

   
    // omitting namespace declarations for now
   
    // print children
    for (int i=0; i < node.getChildCount(); i++) {
      Node child = node.getChild(i);
      result.append(indent);
      result.append(child.toString());
      result.append('\n');
      if (child instanceof Element) { // recurse
        toDebugString((Element)child, depth+1, result);
      }
    }
View Full Code Here

      Document result = factory.startMakingDocument();
      boolean hasRootElement = false;
      int k = 0;
     
      for (int i=0; i < doc.getChildCount(); i++) {
        Node child = doc.getChild(i);
        Nodes nodes;
        if (child instanceof Element) {
          Element elem = (Element) child;
          Element root = factory.makeRootElement(
              elem.getQualifiedName(), elem.getNamespaceURI());
          if (root == null) {
            throw new NullPointerException("Factory failed to create root element.");
          }
          result.setRootElement(root);
          appendNamespaces(elem, root);
          appendAttributes(elem, factory, root);
          build(elem, factory, root);
          nodes = factory.finishMakingElement(root);
        } 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 if (child instanceof DocType) {
          DocType docType = (DocType) child;
          nodes = factory.makeDocType(
              docType.getRootElementName(),
              docType.getPublicID(),
              docType.getSystemID());
        } else {
          throw new IllegalArgumentException("Unrecognized node type");
        }
       
        // append nodes:
        for (int j=0; j < nodes.size(); j++) {
          Node node = nodes.get(j);
          if (node instanceof Element) { // replace fake root with real root
            if (hasRootElement) {
              throw new IllegalAddException(
                "Factory returned multiple root elements");
            }
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.