Org.w3c.dom.Node  isleaf?

Hi all
is there any way to get if a w3c node isLeaf?
I thought that i can see if the first chils ia a text node then i can say that is a leaf but i'm not sure taht is the right way.
Thanks!!

It is not that simple.
In the following chunk:
<a>
  <b>text</b>
</a>the first child of <b> is a text field, so by your premise it is a leaf. But, the first child of <a> is also a text field (the newline and prefix spaces before <b>), so is it a leaf also?
What about:
<html>
  <p>Some text with a highlight <b>ENTRY</b>.</p>
</html>
Is the <p> a leaf?
Perhaps the kind of messages you are trying to parse do not allow nested content. If so, then your concept of "leaf" is really "leaf for a special kind of XML file."

Similar Messages

  • Set Name of org.w3c.dom.Node (= chang the TagNam)

    Hi all,
    How I can set name of my object org.w3c.dom.Node.
    In fact, this is an Element and I want to chang the tag <label> to <LABEL> befort write out DOM to XML File
    thanks a lot
    dseaa

    org.w3c.dom.Element interface does not have a setTagName() method.
    Implement interface org/w3c/dom/contentModel/CMElementDeclaration which has a setTagName() method.
    http://www.w3.org/TR/2001/WD-DOM-Level-3-CMLS-20010419/java-binding.html

  • Problem of using "org.w3c.dom.Node" class

    I try to use removeChild(child) method of "org.w3c.dom.Node" object. it don't work.
    is it better to do child=null;

    child=null does nothing to the dom object
    removeChild works fine. You're just confused.
    You would need more info to have any chance of fixing the problem.

  • Cost of creating org.w3c.dom.Node

    I am trying to create an xml of cached data at run time. I need to know if this would increase the response time considerably ..?
    Is there any documents which talk about the cost of creating nodes(e.g.within loops) ..?
    public Node createnode(Document d, String node_name, int node_value) {
    org.w3c.dom.Node temp_element_node, temp_text_node;
    temp_element_node = d.createElement(node_name);
    temp_text_node = d.createTextNode(node_name);
    temp_text_node.setNodeValue(node_value + "");
    temp_element_node.appendChild(temp_text_node);
    return temp_element_node;
    Has anybody implimented a pool of nodes(like pool of database connections). Any information is appreciated!

    It would certainly depend somewhat on which parser you were using, but i can't imagine it would be any more costly than any other type of object.

  • Adding org.w3c.dom.Node

    Hi,
    can someone please tell me if it is posible do read a org.w3c.dom.Node from one XML file, and than add it to another? Or is there a way to copy one org.w3c.dom.Node to another XML?
    Thanx,
    Alan.

    Refer to
    http://javaalmanac.com/egs/org.w3c.dom/CloneSubtree2.html

  • How to initialize a org.w3c.dom.Node object?

    Hello,
    I want to initialize an org.w3c.dom.Node object with an empty Node.
    How could I do that?
    Thanks
    Sylvain

    I want to create a Document.
    If I test your line, this error appears:
    "Default constructor cannot handle exception type javax.xml.parsers.ParserConfigurationException thrown by implicit super constructor. Must define an explicit constructor."
    Do you know what's happen?
    Thanks
    Sylvain

  • Casting a org.w3c.dom Node to a org.dom4j Node

    Does anybody know how I can cast (convert) a w3c.dom Node to a dom4j Node?
    If I just trying casting the w3c node "(org.dom4j.Node)" it throws an exception...

    I have a org.w3c.dom.Node after calling HttpUnit's getDOMSubtree() method.
    Now I would like to change that Node to an org.dom4j.Node so i can use dom4j's Node.valueOf() method on it.
    Any idea how?

  • How to convert SOAPEnvelope or SOAPBody to org.w3c.dom.Node and vice versa?

    How to convert javax.xml.soap.SOAPEnvelope or javax.xml.soapSOAPBody to org.w3c.dom.Node and vice versa?If this convertion is very diffcult , how to convert String to org.w3c.dom.Node?
    Thanks a lot

    vj008 wrote:
    while parsing a DOM i want to convert
    org.w3c.dom.Element to xml string and after certain processing on that xml string i want to convert back it to
    org.w3c.dom.Element.[This might help. xml transformations in java. |http://tejaspurohit.blogspot.com/2009/08/xml-transformations-in-java.html]

  • NoSuchMethodError with org.w3c.dom.Node.getTextNode()

    Hi,
    I got a trouble with this method. I developped my app with Eclipse and jdk 1.5.
    I used the endrosed mechanism for updating xalan and xerces in my jre.
    Everything works fine on my computer, but as I want to run my app on an other machine, I got this error.
    I put a copy of my jre on the other machine and I launch the app from this jre. It seems the endorsed jars are taken in account, but it still doesn't work.
    Thanks for your help.

    I found ths solution.
    In my jre was missing the endorsed Dom.jar, found at jaxp.dev.java.net. to overwrite org.w3c.dom standard classes.

  • DOMException on executing org.w3c.dom .Node#getNodeValue()

    Hi All,
    I have a query related to Node#getNodeValue(). As per java doc, this call can throw DOMException.
    DOMException - DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in a DOMString variable on the implementation platform.
    Is there a way to upfront figure out that when we call getNodeValue() on given Node , we'll get this exception. In other words, can we check the max size of DOMString with the stored value.
    thanks
    Edited by: user772587 on Mar 29, 2012 8:49 PM

    I do not necessarily understand the question.
    But if you are talking about java with java variable as place holder of the return of getNodeValue() method, then you have the size limit of string of 2 billion bytes long or about, making that exception call practically academic. Image a node value of that long, you would face other problems long before calling a getNodeValue().

  • Org.w3c.dom. node, get number of items

    hi,
    how can i get the number of items of one node?
    thanks

    Have you tried something like - getChildNodes().getLength()?

  • How to add node value using org.w3c.dom.Document?

    Hi ,
    I'm using org.w3c.dom.Document to deal with xml files. I could successfully add nodes , and their attributes. However I could not add a value of the node. (e.g. <myNode>I couldn't add this value</myNode>)
    does anyone know how to deal with this?
    I tried subNode.setNodeValue("the value i can't add"); whereas the subNode is an instance of org.w3c.dom.Node... i know this is interface i of course used the concrete class
    org.apache.crimson.tree.ElementNode
    but when I used the subNode.getNodeValue() i simply got null?
    can u plz help me?
    thanks in advance

    Reading the API documentation for the Node interface might help. At least you wouldn't be surprised when the results are exactly what the documentation says they will be.
    What would really help would be forgetting the idea that an Element can have a value. Text nodes have values, though, so create a Text node and make it the child of the Element node.

  • How to create org.w3c.dom.Document.

    Hi,
    I have my complete xml file in a String variable like
    String strXml = " <?xml version="1.0"?>
    <report>
    <name>testReport & report
    <duration>Jan to Feb</duration>
    <reportId>1</reportId>
    </report> "
    I need to create a "org.w3c.dom.Document" object from the above "strXml" variable.
    Thanks in advance for your answers,
    Sha S.

    this is the code snippet that would answer u r question
    import org.apache.xml.serialize.XMLSerializer;
    import org.w3c.dom.Attr;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Text;
    import org.w3c.dom.ProcessingInstruction;
    import org.xml.sax.InputSource;
    import com.exel.businessobjects.*;
    StringReader srxml = new StringReader(xmlcontent);
    Reader rxml     = (Reader)srxml;
    InputSource isxml = new InputSource(rxml);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(isxml);

  • Save org.w3c.dom.Document to XMLFile (cont.): NoSuchMethodError

    Hi all,
    I have just download the newest package JavaTM API for Java API for XML Processing 1.2 (URL: http://jsecom16d.sun.com/ECom/EComTicketServlet/BEGINjsecom16d.sun.com-65eb%3A3e840f19%3A4aa0f3743cc56218/76867611/195076095/1/209642/209642/76867611-195076095/xmzZndezB81HYlfGYdXI/westCoastFSEND/ESD2/commsrc/JAXP/1.2/jaxp-1_2_0-scsl.zip) and builded it with Apache Ant 1.4.1 => I have 6 jars: - dom.jar - sax.jar - jaxp-api.jar - xercesImpl.jar - xalan.jar - xsltc.jar
    But when I follows the guide in tutorial Writing Out a DOM as an XML File (URL http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html:)
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    DOMSource source = new DOMSource(m_Document);
    StreamResult result = new StreamResult(new File(fileName));
    transformer.transform(source, result);
    I hit an error:
    java.lang.NoSuchMethodError: org.w3c.dom.Node: method getNamespaceURI()Ljava/lang/String; not found at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:478)
         at vn.vnteam.letter.XMLWriter.save(XMLWriter.java:166)
         at vn.vnteam.letter.Templet.main(Templet.java:254)
    Exception in thread "main"
    I see in file org.w3c.dom.Node.class there is function String getNamespaceURI();
    but there is no such function in org.apache.xalan.transformer.TransformerIdentityImpl.
    now what I have to do, please?
    Thanks a lot
    best regards
    Hai

    That method is supported in Document Object Model (DOM) Level 2 only.

  • Org.w3c.dom.Element to javax.xml.soap.SOAPElement

    I have a org.w3c.dom.Element that I want to insert into an existing SOAPBody using
    public SOAPElement addChildElement(SOAPElement element). How can I turn the org.w3c.dom.Element
    into a javax.xml.soap.SOAPElement so that I can do that?
    Steve Watson

    Hi Steve,
    Here's a code segment that may be of some value.
    Bruce
         public SOAPElement populateSOAPElement(SOAPEnvelope envelope,
    SOAPElement element, Element sndElement) throws SOAPException{
    int i, j;
    NamedNodeMap map;
    Node node;
    NodeList list;
    SOAPElement subElement;
    //populate attributes
    map = sndElement.getAttributes();
    for (j = 0; j < map.getLength(); j ++)
    node = map.item(j);
    element.addAttribute(envelope.createName(node.getNodeName()),
    sndElement.getAttribute(node.getNodeName()));
    //populate the element value and subElements
    list = sndElement.getChildNodes();
    for (j = 0; j < list.getLength(); j ++)
    short type = list.item(j).getNodeType();
    String typeString = "";
    if (list.item(j).getNodeType() == 3)
    element.addTextNode(list.item(j).getNodeValue());
    if(list.item(j).getNodeType() == 1)
    subElement =
    element.addChildElement(((Element)list.item(j)).getTagName());
    subElement = populateSOAPElement(envelope, subElement,
    (Element)list.item(j));
    return element;
    Steve wrote:
    >
    I have a org.w3c.dom.Element that I want to insert into an existing SOAPBody using
    public SOAPElement addChildElement(SOAPElement element). How can I turn the org.w3c.dom.Element
    into a javax.xml.soap.SOAPElement so that I can do that?
    Steve Watson

Maybe you are looking for