Package nu.xom

Examples of nu.xom.Node


        Nodes included;
        if (xpointer != null && xpointer.length() != 0) {
            included = XPointer.query(doc, xpointer);
            // fill in lang attributes here
            for (int i = 0; i < included.size(); i++) {
                Node node = included.get(i);
                // Current implementation can only select elements
                Element top = (Element) node;
                Attribute lang = top.getAttribute("lang",
                  "http://www.w3.org/XML/1998/namespace");
                if (lang == null) {
                    String childLanguage = getXMLLangValue(top);
                    if (!parentLanguage.equals(childLanguage)) {
                        top.addAttribute(new Attribute("xml:lang",
                          "http://www.w3.org/XML/1998/namespace",
                          childLanguage));
                    }
                }
            }
        }
        else {
            included = new Nodes();
            for (int i = 0; i < doc.getChildCount(); i++) {
                Node child = doc.getChild(i);
                if (!(child instanceof DocType)) {
                    included.append(child);
                }           
            }
        }
        // so we can detach the old root if necessary
        doc.setRootElement(new Element("f"));
        for (int i = 0; i < included.size(); i++) {
            Node node = included.get(i);
            // Take account of xml:base attribute, which we normally
            // don't do when detaching
            String noFragment = node.getBaseURI();
            if (noFragment.indexOf('#') >= 0) {
                noFragment = noFragment.substring(0, noFragment.indexOf('#'));
            }
            node.detach();
            if (node instanceof Element) {
                ((Element) node).setBaseURI(noFragment);
            }
        } 
         
View Full Code Here


    private static Element findNthChildElement(
      ParentNode parent, int position) { 
        // watch out for 1-based indexing of tumblers
        int elementCount = 1;
        for (int i = 0; i < parent.getChildCount(); i++) {
            Node child = parent.getChild(i);
            if (child instanceof Element) {
                if (elementCount == position) return (Element) child;  
                elementCount++;
            }
        }
View Full Code Here

    }
   
   
    static Element findByID(Element element, String id) {
        
        Node current = element;
        boolean end = false;
        int index = -1;
        while (true) {
           
            if (current instanceof Element) {
                Element currentElement = (Element) current;
                for (int i = 0; i < currentElement.getAttributeCount(); i++) {
                    Attribute att = currentElement.getAttribute(i);
                    if (att.getType() == Attribute.Type.ID) {
                        if (att.getValue().trim().equals(id)) {
                            return currentElement;  
                        }
                    }  
                }
            }
           
            if (!end && current.getChildCount() > 0) {
               current = current.getChild(0);
               index = 0;
            }
            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 {
View Full Code Here

        Element root = new Element("root");
        Document doc = new Document(root);
        doc.setBaseURI("http://www.example.com");
        Element child = new Element("child");
        root.appendChild(child);
        Node copy = child.copy();
        assertEquals("http://www.example.com", copy.getBaseURI());
       
    }
View Full Code Here

    public void testTriple()
      throws IOException, ParsingException
        String data = "<b><c1 /><c2 /></b>";
        Builder builder = new Builder();
        Document doc = builder.build(data, "http://www.example.org/");
        Node root = doc.getRootElement();
        Node rootcopy = root.copy();
        assertEquals(data, rootcopy.toXML());     
    }   
View Full Code Here

   
    public void testEmptyElementAsRootElementCopy() {
       
        Element root = new Element("root");
        Document doc = new Document(root);
        Node copy = doc.copy();
        assertEquals(doc, copy);
    }
View Full Code Here

        Element parent = new Element(name, uri);

        Attribute a1 = new Attribute("test", "test");      
        parent.addAttribute(a1);
       
        Node child1 = new Text("http://www.mauve.com");
        parent.appendChild(child1);
        Node child2 = new ProcessingInstruction(
          "child", "http://www.mauve.com");
        parent.appendChild(child2);
        Node child3 = new Comment("http://www.mauve.com");
        parent.appendChild(child3);
 
        assertEquals(parent, child3.getParent());
        assertEquals(parent, child1.getParent());
        assertEquals(parent, child2.getParent());
      
        Nodes result = parent.removeChildren();
        assertEquals(0, parent.getChildCount());
        assertNull(child1.getParent());
        assertNull(child2.getParent());
        assertNull(child3.getParent());
        assertEquals(parent, a1.getParent());
       
        assertEquals(3, result.size());
        assertEquals(child1, result.get(0));
        assertEquals(child2, result.get(1));
View Full Code Here

                      pg = 0;
                        tokText = m.group(0);
                    }
                   
                    textNode.setValue(txt.substring(0, m.start()));
                    Node currentNode = textNode;
                    if(m.start(pg) > m.start()) {
                      Text invincibleText =
                        new Text(txt.substring(m.start(), m.start(pg)));
                      XOMTools.insertAfter(currentNode, invincibleText);
                      currentNode = invincibleText;                       
View Full Code Here

      nodeDict = new HashMap<String,String>();
      // create top RPNode
      topNode = new RPNode(this);

      // find <child> within <top> and add them to topNode
      Node top = doc.query("//top").get(0);
      for(int i=0;i<top.getChildCount();i++) {
        Node child = top.getChild(i);
        if(child instanceof Element) {
          Element childElem = (Element)child;
          if("child".equals(childElem.getLocalName())) {
            // child is of type <child>
            String type = childElem.getAttributeValue("type");
            String id = childElem.getAttributeValue("id");
            // find the <node> the <child> refers to
            Node node2 = findNode(type, id);
            if(node2==null)
              continue;
            // node2 is the <node> referred to by <child>
            // get value attribute, if exists, else null
            topNode.addChild((Element)node2);                          
View Full Code Here

       
   
    String getNodeText(Element node) {
        StringBuffer txt = new StringBuffer();
        for(int i=0;i<node.getChildCount();i++) {
          Node child = node.getChild(i);
          if(child instanceof Text) {
                    txt.append(child.getValue());
          } else if(child instanceof Element) {
            Element childElem = (Element)child;
            if(childElem.getLocalName().equals("insert")) {
              String tag = childElem.getAttributeValue("idref");
              txt.append(getDefText(tag));
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.