Package nu.xom

Examples of nu.xom.ParentNode


            }
       
            for (int i = 0; i < elementSchemeData.size(); i++) {
                String currentData = (String) (elementSchemeData.get(i));
                int[] keys = new int[0];
                ParentNode current = doc;
                if (currentData.indexOf('/') == -1) {
                    // raw id in element like element(f2)
                    try {
                        new Element(currentData);
                    }
View Full Code Here


            else {
                if (end) {
                    if (current == element) break;
                }
                end = false;
                ParentNode parent = current.getParent();
                if (parent.getChildCount() - 1 == index) {
                    current = parent;
                    if (current != element) {
                        parent = current.getParent();
                        index = parent.indexOf(current);
                    }
                    end = true;
                }
                else {
                    index++;
                    current = parent.getChild(index);
                }
            }
        } 
       
        return null;
View Full Code Here

    *
    * @param node The reference node.
    * @return The next Sibling, or null.
    */ 
  public static Node getNextSibling(Node node) {
    ParentNode parent = node.getParent();
    int i = parent.indexOf(node);
    if (i+1 >= parent.getChildCount()) return null;
    return parent.getChild(i+1);
  }
View Full Code Here

    *
    * @param node The reference node.
    * @return The previous Sibling, or null.
    */
  public static Node getPreviousSibling(Node node) {
    ParentNode parent = node.getParent();
    int i = parent.indexOf(node);
    if (i==0) return null;
    return parent.getChild(i-1);
  }
View Full Code Here

     *
     * @param node The reference node.
     * @param newNode The new node to insert.
     */
  public static void insertBefore(Node node, Node newNode) {
    ParentNode parent = node.getParent();
    int i = parent.indexOf(node);
    parent.insertChild(newNode, i);
  }
View Full Code Here

     *
     * @param node The reference node.
     * @param newNode The new node to insert.
     */
  public static void insertAfter(Node node, Node newNode) {
    ParentNode parent = node.getParent();
    int i = parent.indexOf(node);
    parent.insertChild(newNode, i+1);
  }
View Full Code Here

   * instances of a Text node next to another Text node are created.
   *
   * @param elem The element to remove from the document.
   */
  public static void removeElementPreservingText(Element elem) {
    ParentNode parent = elem.getParent();
    /* Put fingers on relevant nodes */
    Node previous = XOMTools.getPreviousSibling(elem);
    Node next = XOMTools.getNextSibling(elem);
    int index = elem.getParent().indexOf(elem);
    if(elem.getChildCount() > 0) {
      /* Put fingers on relevant inner nodes */
      Node contentsFirst = elem.getChild(0);
      Node contentsLast = elem.getChild(elem.getChildCount()-1);
      /* Transfer inner nodes to parent */
      while(elem.getChildCount() > 0) {
        Node nn = elem.getChild(0);
        nn.detach();
        parent.insertChild(nn, index);
        index++;
      }
      /* Perform Text surgery */
      if((previous instanceof Text) && (contentsFirst instanceof Text)) {
        ((Text)previous).setValue(previous.getValue() + contentsFirst.getValue());
View Full Code Here

  public void removeProcessingInstructions() {
    procInstructions = new ArrayList<ProcessingInstruction>();
    Nodes piNodes = pubXMLDoc.getRootElement().query(".//processing-instruction()");
    for(int i=0;i<piNodes.size();i++) {
      ProcessingInstruction pi = (ProcessingInstruction)piNodes.get(i);
      ParentNode piParent = pi.getParent();
      int index = piParent.indexOf(pi);
      Element e = new Element("pi-proxy");
      e.addAttribute(new Attribute("pinumber", Integer.toString(i)));
      pi.detach();
      piParent.insertChild(e, index);
      procInstructions.add(pi);
    }   
  }
View Full Code Here

 
  public void replaceProcessingInstructions(Document newPubDoc) {
    Nodes proxyNodes = newPubDoc.query("//pi-proxy");
    for(int i=0;i<proxyNodes.size();i++) {
      Element e = (Element)proxyNodes.get(i);
      ParentNode eParent = e.getParent();
      int index = eParent.indexOf(e);
      int pin = Integer.parseInt(e.getAttributeValue("pinumber"));
      ProcessingInstruction pi = procInstructions.get(pin);
      e.detach();
      eParent.insertChild(pi, index);
    }       
  }
View Full Code Here

        //System.out.println("//s[@sid='" + sentid + "']");
        Elements sentenceChildren = sentenceElement.getChildElements();
        for(int j = 0; j < sentenceChildren.size(); j++) {
          //System.out.println(sentenceChildren.get(j));
        }
        ParentNode parent = sentenceElement.getParent();
        int childIndex = parent.indexOf(sentenceElement);
        sentenceElement.detach();
       
        //Elements sentenceContent = sentenceElement.getChildElements();
        //System.out.println("content of sentence: " + sentenceContent);
        ArrayList<Attribute> attArray = new ArrayList<Attribute>();
        attArray.add(new Attribute("atype", "GSC"));
        if(!ctype.equals("None")) {
          ///System.out.println("ctype is not None: " + ctype);
          attArray.add(new Attribute("type", ctype.substring(0, 3)));
        } else {
          //System.out.println("ctype is None:" + ctype);
          attArray.add(new Attribute("type", ctype));
        }
        attArray.add(new Attribute("conceptID", ctype));
        attArray.add(new Attribute("novelty", novelty));
        attArray.add(new Attribute("advantage", advantage));
        Element annotationElement = new Element("annotationART");
        for (Attribute a: attArray) {
          annotationElement.addAttribute(a);
        }
        //System.out.println(annotationElement);
        //annotationElement.appendChild("<dummy tag='this'>hello</dummy>");
        //Text textNode = new Text(untaggedSentence);
        annotationElement.appendChild(unchevronned);
       
        /*for(int i = 0; i <sentenceContent.size();i++) {
          sentenceElement.removeChild(sentenceContent.get(i));
          annotationElement.appendChild(sentenceContent.get(i));
          System.out.println("child:" + sentenceContent.get(i).toString());
        }*/
        //sentenceElement.removeChildren();
       
        Element newSentence = new Element("s");
        parent.insertChild(newSentence, childIndex);
        Attribute sidAttr = new Attribute("sid", sentid);
        newSentence.addAttribute(sidAttr);       
        newSentence.appendChild(annotationElement);
        //System.out.println(newSentence.toString());
      }
View Full Code Here

TOP

Related Classes of nu.xom.ParentNode

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.