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.

Similar Messages

  • How to Convert SOAPMessage to a org.w3c.dom.Document object?

    See the subject.

    Hi,
    by reading the DOM4J documentation (www.dom4j.org), I have seen that a very useful org.dom4j.dom package exists.
    You can then use the org.dom4j.io.DOMWriter class to convert the SOAP structure in a DOM tree by using the DOMWriter.write() method.
    Because I wanted to convert only the body part of the SOAP message in a DOM tree, I am using the following code :
    // Extract the SOAP body
    SOAPBody body = ...
    // Get the first element of the body by using the SOAP methods
    SOAPElement eRoot = ...
    // Creates a SAXSource from the DOM4J element
    javax.xml.transform.sax.SAXSource saxSource = new org.dom4j.io.DocumentSource ((org.dom4j.Element)eRoot);
    // You can then use directly use this javax.xml.transform.Source object
    // or get only the InputSource needed to parse a DOM tree
    org.xml.sax.InputSource source = saxSource.getInputSource();
    // Use this source with a JAXP parser for example
    // ...Regards,
    Damien.

  • Org.w3c.dom.Document to/from String ?

    I need to be able to parse (once) an XML string, and then pass the parsed object around to/from different objects.
    I tried to use org.w3c.dom.Document,
    generated by javax.xml.parsers.DocumentBuilder .
    HOWEVER - I don't see any way to parse an xml String!
    The doc-builder parse() method accepts either a file/url, or an InputStream.
    When I tried to use the StringBufferInputStream I found-out it is deprecated, and that I should use StringReader.
    BUT I cannot parse using StringReader ! (the method parse() doesn't work with it)
    Is there anyway to parse a String to create a Document ?
    ========================================================
    And that's only HALF my problem:
    I did parse an input file into a Document, to experiment a little.
    I then wanted to convert it to an XML String - but couldn't.
    How do I get the xml String from a Document ?
    I cannot: How do I save it to a file ?
    I must say that under .NET both tasks are TRIVIAL:
    XmlDocument.LoadXML()
    XmlDocument.OuterXml
    Thanks
    Meir

    The doc-builder parse() method accepts either a file/url, or an InputStream.This isn't true. Look it up again. There are overridden versions of parse() that use File, InputSource, InputStream, or String. The String one isn't what you want, because the String it takes is a URL pointing to the XML and not the XML itself. The File one doesn't work for you because you don't have a file, and you've already said why the InputStream one doesn't work for you.
    So that leaves the version that takes an InputSource. So, what is an InputSource anyway? You could look it up just by clicking on the link in the API docs...

  • How to convert clobDomain to org.w3c.dom.Document

    Hi
    We have store the xml data into oracle database as clobDomain.We are reading the same data from db and want to convert it into org.w3c.dom.Document type.We used the method getXMLContentNode() but its doesn't help us.See the below code.
    ClobDomain pedigreeXML = (ClobDomain) pedigreeDocumentRow.getAttribute("PedigreeDocument");
    DocumentBuilderFactory docBuildFactory= DocumentBuilderFactory.newInstance();
    Document containerDoc = docBuildFactory.newDocumentBuilder().newDocument();
    System.out.println(containerDoc.toString()); // this sop statement printing the xml fine
    Node node= pedigreeXML.getXMLContentNode(containerDoc);
    System.out.println(node); // this sop statement is printing data as "oracle.xml.parser.v2.XMLCDATA@1de6ded"
    Please let me know can we convert clobDomain to Document type.
    Thanks
    Baji

    Baji,
    it would help if you give the jdev version you are working on...
    I don't see a problem with the output you get from System.out.println(node); // this sop statement is printing data as "oracle.xml.parser.v2.XMLCDATA@1de6ded"as it only prints you the address of the node, but not the content. Try
    String str = node.getTextContent();and check if this get you the content.
    Timo

  • How to parse & update org.w3c.dom.Document

    Hi,
    I have a org.w3c.dom.Document "w3Doc" object which is converted to org.jdom.Document object using DOMBuilder().build(w3Doc) method.
    Now the problem which I'm facing is that this org.w3c.dom.Document object contains an illegal xml character & when DOMBuilder().build() method tries to create JDOM doc/tree from org.w3c.dom.Document it raises IllegalDataException & the application errors up.
    Now, I want to parse org.w3c.dom.Document "w3Doc" object & check for illegal xml character in the w3Doc & remove this character.
    Can anyone help me out in finding which parser should I use to read w3Doc & update the doc(by removing the illegal data).
    Thanks in advance,

    Normally a Document is the output of a parser, not the input to one. And all the parsers I know of will not allow invalid XML characters to pass. So it must be that you're creating Text nodes in your program that include invalid XML characters and adding them to a Document. (I'm surprised that the DOM implementation allows you to do that.)
    So you should just stop doing that, instead of trying to find something to clean up the mess after the fact. The XML Recommendation, in section 2.2, tells you what characters are valid in XML. You can find it here:
    http://www.w3.org/TR/REC-xml/

  • How to convert org.dom4j.Document into org.w3c.dom.Document  ?

    Hi,
    I have done googling for how to convert org.dom4j.Document into org.w3c.dom.Document , but could not get any usefull data.
    If any one is having solution or any idea, please reply.
    Thanks in advance
    <!--Session data-->

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • 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);

  • How to put org.w3c.dom.Document into String

    Hello!
    I have some sample xml file with xml schema (xsd file). After parsing this sample file into org.w3c.dom.Document I would like to put it into the string and print out for test purpose only. But I don't know how to do it.
    I would like to print something like
    <somebody>
    <first>First somenthing</first>
    <second>Second something</second>
    </somebody>
    Thanks for your advices.

    The function you have specified works fine and gives back the string from DOM object.But it ruins all the formatting associated with the XML (like new line character)
    Is there any way to overcome it?
    Currently if i have a xml as
    <student>
    <firstname>
    </firstname>
    </student>
    The output of the code u have sent strips off the new line characters and returns everything in a single line as below:
    <student> <firstname> </firstname> </student>
    Thanks for any help associated with above problem.

  • Problem casting org.w3c.dom.Document to oracle.xml.parser.v2.XMLDocument

    I have the following problem:
    I get my xml-documents as an XMLType from the database and want to compare these using the supplied Oracle class oracle.xml.differ.XMLDiff (i use the java version supplied with Oracle 9i r2).
    XMLType.getDOM() returns the xml-document as a org.w3c.dom.Document,
    what i need for oracle.xml.differ.XMLDiff is a oracle.xml.parser.v2.XMLDocument.
    How can i cast/convert between these two formats?
    thanks!
    p.s. cross-posting with Re: Casting/Converting XMLType to XMLDocument? (but i think this forum is more relevant).

    Hi,
    thanks for the suggestion: i have written the code shown below. It results in a casting error.
    As far as i know, i don't use a oracle.xdb.dom.XDBDocument, i only use a oracle.xdb.XMLType as the input parameter for my conversion-method:
    any new suggestions ???
    p.s. the second method which is commented does work, but is a bit verbose.
       private static oracle.xml.parser.v2.XMLDocument convert2XMLDocument(XMLType xml) {
         // simple version (should work according to tech. doc. 9i r2/ 10g r1 database)
         oracle.xml.parser.v2.XMLDocument doc = null;
         try {
            // n.b. probleem is dat XMLType.getDOM() een w3c.Document object teruggeeft ipv een oracle.XMLDocument.
            System.out.println("convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.");
            doc = (oracle.xml.parser.v2.XMLDocument) xml.getDOM(); // public org.w3c.dom.Document getDOM()
            System.out.println("convert2XMLDocument(): done casting w3c.Document naar oracle.XMLDocument.");
         catch (Exception e) {
            e.printStackTrace(System.out);
        return doc;
       private static XMLDocument convert2XMLDocument(XMLType xml) {
         // complex version: works ok !!!
         XMLDocument doc = null;
         try{
            DOMParser parser  = new DOMParser();
            parser.setValidationMode(oracle.xml.parser.v2.XMLParser.NONVALIDATING);
            parser.setPreserveWhitespace (true);   
            parser.parse(new StringReader(xml.getStringVal()));
            doc = parser.getDocument();
        catch ( XMLParseException e ) {
          e.printStackTrace(System.out);
        catch ( SQLException e ) {
          e.printStackTrace(System.out);
        catch ( Exception e ) {
          e.printStackTrace(System.out);
        return doc;
    convert2XMLDocument(): casting w3c.Document naar oracle.XMLDocument.
        java.lang.ClassCastException: oracle.xdb.dom.XDBDocument
         at pnb.bdb.xml.testJDBC.convert2XMLDocument(testJDBC.java:305)
         at pnb.bdb.xml.testJDBC.main(testJDBC.java:187)

  • Java.lang.StackOverflowError when invoking a method, returning a org.w3c.dom.Document object, on a SessionBean

    Hello,
    I hope someone can help me with this.
    I have a stateless session bean, which is returning a
    org.w3c.dom.Document object. The whole object is getting created
    but at the client side I am getting the following exception:
    java.rmi.RemoteException: ; nested exception is:
    weblogic.rmi.ServerError: A RemoteException occurred in the server method
    - with nested exception:
    [java.lang.StackOverflowError:
    Start server side stack trace:
    java.lang.StackOverflowError
    at java.lang.Exception.<init>(Compiled Code)
    at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetEx
    ception.java:58)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Compiled Code)
    at java.io.ObjectOutputStream.invokeObjectWriter(Compiled Code)
    at java.io.ObjectOutputStream.outputObject(Compiled Code)
    at java.io.ObjectOutputStream.writeObject(Compiled Code)
    at java.io.ObjectOutputStream.outputClassFields(Compiled Code)
    at java.io.ObjectOutputStream.defaultWriteObject(Compiled Code)
    Then multiple occurences of the last few lines followed by
    at org.apache.xerces.dom.ParentNode.writeObject(Compiled Code)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Compiled Code)
    at java.io.ObjectOutputStream.invokeObjectWriter(Compiled Code)
    at java.io.ObjectOutputStream.outputObject(Compiled Code)
    at java.io.ObjectOutputStream.writeObject(Compiled Code)
    at java.io.ObjectOutputStream.outputClassFields(Compiled Code)
    at java.io.ObjectOutputStream.defaultWriteObject(Compiled Code)
    at org.apache.xerces.dom.ParentNode.writeObject(Compiled Code)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Compiled Code)
    at java.io.ObjectOutputStream.invokeObjectWriter(Compiled Code)
    at java.io.ObjectOutputStream.outputObject(Compiled Code)
    at java.io.ObjectOutputStream.writeObject(Compiled Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeObject(Compiled
    Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeSpecial(Compiled
    Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeObject(Compiled
    Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeObjectWL(Compiled
    Code)
    at weblogic.rmi.extensions.AbstractOutputStream2.writeObject(Compiled
    Code)
    at com.ssmb.teams.model.CMSInterestDataEJBEOImpl_WLSkel.invoke(Compiled
    Code)
    at weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(Compiled Code
    at weblogic.rmi.extensions.BasicRequestHandler.handleRequest(Compiled
    Code)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(Compiled Code)
    at weblogic.kernel.ExecuteThread.run(Compiled Code)
    End server side stack trace
    at weblogic.rmi.extensions.AbstractRequest.sendReceive(AbstractRequest.j
    ava:76)
    at com.ssmb.teams.model.CMSInterestDataEJBEOImpl_WLStub.getRegionAnalyst
    Data(CMSInterestDataEJBEOImpl_WLStub.java:558)
    at com.ssmb.teams.model.CMSInterestDataEJBEOImpl_ServiceStub.getRegionAn
    alystData(CMSInterestDataEJBEOImpl_ServiceStub.java, Compiled Code)
    at CMSJavaScript.main(CMSJavaScript.java:87)
    The structure of the XML document is
    <Maillist>
         <Region>
              <RegionCode>7</RegionCode>
              <RegionName>Asia Pacific</RegionName>
              <Analyst>
                   <Id>11111</Id>
                   <Name>AAAAAAAAAAAAAAAAA</Name>
              </Analyst>
              <Analyst>
                   <Id>22222</Id>
                   <Name>BBBBBBBBBBBBBBBBBB</Name>
              </Analyst>
         </Region>
    </Maillist>
    If the no. of Anlayst elements are 219, I am getting this error ( the same thing
    is working for less no. of analyst).
    Surprisingly when I access this ejb, by deploying it on my local server instance
    on Win-NT, it works fine. I am getting this
    exception, when the server is running on Sun Solaris.
    The weblogic version is 5.1.
    It will be really helpful if someone can reply to mee ASAP
    Thanks.
    Suren.

    Thanks a lot guys for all that information.
    Rajesh Mirchandani <[email protected]> wrote:
    Suren,
    More info at
    http://edocs.bea.com/wls/docs60/faq/java.html#251197
    Rob Woollen wrote:
    The quick fix is probably to use the -Xss argument on the Solaris JVMto increase the
    thread stack size.
    -- Rob
    Suren wrote:
    Thanks for your quick response.
    But how do we overcome with this?
    I tried to look for some help with this, but if you have any idea,
    can you suggest
    something ?
    Thanks
    Suren.
    Rob Woollen <[email protected]> wrote:
    It looks like the stack is overflowing when your DOM Tree is being
    serialized.
    Perhaps the Solaris JVM has a lower stack size by default.
    -- Rob
    Suren wrote:
    Hello,
    I hope someone can help me with this.
    I have a stateless session bean, which is returning a
    org.w3c.dom.Document object. The whole object is getting created
    but at the client side I am getting the following exception:
    java.rmi.RemoteException: ; nested exception is:
    weblogic.rmi.ServerError: A RemoteException occurred in
    the
    server method
    - with nested exception:
    [java.lang.StackOverflowError:
    Start server side stack trace:
    java.lang.StackOverflowError
    at java.lang.Exception.<init>(Compiled Code)
    at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetEx
    ception.java:58)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Compiled Code)
    at java.io.ObjectOutputStream.invokeObjectWriter(Compiled
    Code)
    at java.io.ObjectOutputStream.outputObject(Compiled Code)
    at java.io.ObjectOutputStream.writeObject(Compiled Code)
    at java.io.ObjectOutputStream.outputClassFields(CompiledCode)
    at java.io.ObjectOutputStream.defaultWriteObject(CompiledCode)
    Then multiple occurences of the last few lines followed by
    at org.apache.xerces.dom.ParentNode.writeObject(CompiledCode)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Compiled Code)
    at java.io.ObjectOutputStream.invokeObjectWriter(CompiledCode)
    at java.io.ObjectOutputStream.outputObject(Compiled Code)
    at java.io.ObjectOutputStream.writeObject(Compiled Code)
    at java.io.ObjectOutputStream.outputClassFields(CompiledCode)
    at java.io.ObjectOutputStream.defaultWriteObject(CompiledCode)
    at org.apache.xerces.dom.ParentNode.writeObject(CompiledCode)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Compiled Code)
    at java.io.ObjectOutputStream.invokeObjectWriter(CompiledCode)
    at java.io.ObjectOutputStream.outputObject(Compiled Code)
    at java.io.ObjectOutputStream.writeObject(Compiled Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeObject(Compiled
    Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeSpecial(Compiled
    Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeObject(Compiled
    Code)
    at weblogic.common.internal.WLObjectOutputStreamBase.writeObjectWL(Compiled
    Code)
    at weblogic.rmi.extensions.AbstractOutputStream2.writeObject(Compiled
    Code)
    at com.ssmb.teams.model.CMSInterestDataEJBEOImpl_WLSkel.invoke(Compiled
    Code)
    at weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(CompiledCode
    at weblogic.rmi.extensions.BasicRequestHandler.handleRequest(Compiled
    Code)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(CompiledCode)
    at weblogic.kernel.ExecuteThread.run(Compiled Code)
    End server side stack trace
    at weblogic.rmi.extensions.AbstractRequest.sendReceive(AbstractRequest.j
    ava:76)
    at com.ssmb.teams.model.CMSInterestDataEJBEOImpl_WLStub.getRegionAnalyst
    Data(CMSInterestDataEJBEOImpl_WLStub.java:558)
    at com.ssmb.teams.model.CMSInterestDataEJBEOImpl_ServiceStub.getRegionAn
    alystData(CMSInterestDataEJBEOImpl_ServiceStub.java, Compiled
    Code)
    at CMSJavaScript.main(CMSJavaScript.java:87)
    The structure of the XML document is
    <Maillist>
    <Region>
    <RegionCode>7</RegionCode>
    <RegionName>Asia Pacific</RegionName>
    <Analyst>
    <Id>11111</Id>
    <Name>AAAAAAAAAAAAAAAAA</Name>
    </Analyst>
    <Analyst>
    <Id>22222</Id>
    <Name>BBBBBBBBBBBBBBBBBB</Name>
    </Analyst>
    </Region>
    </Maillist>
    If the no. of Anlayst elements are 219, I am getting this error( the
    same thing
    is working for less no. of analyst).
    Surprisingly when I access this ejb, by deploying it on my local
    server
    instance
    on Win-NT, it works fine. I am getting this
    exception, when the server is running on Sun Solaris.
    The weblogic version is 5.1.
    It will be really helpful if someone can reply to mee ASAP
    Thanks.
    Suren.

  • Security Exception in trying to get a org.w3c.dom.Document

    Hi,
    I'm trying to get an org.w3c.dom.Document using the following code----
         String configFileName = "discoveryconsts.xml";
              DocumentBuilder db = null;
              Document xmlDocument = null;
              DocumentBuilderFactory dbf = null;
         dbf = DocumentBuilderFactory.newInstance();
    System.out.println("The DocumentBuilderFactory is :" + dbf);     
    //the exception happens here,while building the DocumentBuilder.
         db = dbf.newDocumentBuilder();
    System.out.println("The DocumentBuilder is :" + db);          try
         xmlDocument = db.parse(configFileName);
    System.out.println("The Document Builder is :" + db);
    catch(Exception e)
         System.out.println("The Exception is :"+ e);
    System.out.println("The XML Document is :" + xmlDocument);
    The error obtained is in the ---
    java.lang.SecurityException: sealing violation
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:234)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(DocumentBuilderImpl.java:98)
    atorg.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(DocumentBuilderFactoryImpl.java:87)
    at Prototype.ChangingDiscConstsFile.discoveryConstants(ChangingDiscConstsFile.java:36)
    at Prototype.ChangingDiscConstsFile.main(ChangingDiscConstsFile.java:74)
    This error is obtained at runtime(ie.The file gets compiled).
    Kindly let me know the reason for the exception.
    regards,
    Karan.

    Hello Satya,
    Have you checked if the cross domain security between the domain WLS 10.3.5 and the backend server is enabled?
    Trust between domains is established so that principals in a Subject from one WebLogic domain can make calls in another domain. In previous releases of WebLogic Server, there was only one type of domain trust that is now referred to as Global Trust. WebLogic Server now supports a type of domain trust that is referred to as Cross Domain Security. The following sections explain how to configure each domain trust type:
    Enabling Cross Domain Security Between WebLogic Server Domains
    Enabling Global Trust
    http://docs.oracle.com/cd/E21764_01/web.1111/e13707/domain.htm#i1176046

  • Covert org.jdom.Document to org.w3c.dom.Document

    Hello,
    How would I convert org.jdom.Document to org.w3c.dom.Document??
    I'm creating org.jdom.Document from the servlet that reads from the database, which gets output like following.
    // doc is org.jdom.Document
    Document doc = new Document( root );
    reportName = new Element( "REPORT_NAME" );
    root.addContent( reportName );
    reportName.setText( "Current Account Balance" );
    // skip...
    XMLOutputter outputter = new XMLOutputter(" ", true, "UTF-8");
    outputter.output(doc, out);
    And in my caller servlet, I read from the previous servlet using URL and parse it, trying to get Document, but it
    InputSource xmlSource = new InputSource( url.openStream());
    //Use a DOM Parser (org.apache.xerces.parsers.DOMParser)
    DOMParser parser = new DOMParser();
    parser.parse( xmlSource );
    Document doc = parser.getDocument();
    // and I do transformation.
    DOMSource inXML = new DOMSource( doc );
    StreamResult outXML = new StreamResult( out );
    transformer.transform( inXML, outXML )
    I'd like to skip passing around XML and share the same Document object so that I don't have parse it again...
    Help!

    Convert jdom document to dom document with class DOMOutputter.
    org.jdom.output.DOMOutputter domOut=new DOMOutputter();
    org.w3c.dom.Document domDocument=domOut.output(org.jdom.Document jdomDocument);

  • Org.w3c.dom.Document.getElementById() not working for me

    I am having trouble using the .getelementById for the org.w3c.dom.Document class. I have devised a workaround, but was wondering what I have been doing wrong in the first place.
    My XML file contains, in part, a bunch of "sections" as outlined below:
    <section id="uniqueString">
       <icon ... />
       <window ... />
    </section>I want to get a "section" whose ID is String s . I tried using .getElementById()
    // document is of class org.w3c.dom.Document, and has parsed in an XML file
    // String s = "uniqueString"
    Element e = document.getElementById(s);However, e is null every time I run this. I have tried it with different Strings which look for other XML tags, but it always is null . I have devised a workaround:
    NodeList sections = document.getElementsByTagName("section");
    for (int i = 0; i < sections.getLength(); ++i) {
         if (((Element) sections.item(i)).getAttribute("id").equals(s)) {
              e = (Element) sections.item(i);
    // Do something with eSo the functionality I need is there; however, I was just wondering if anybody sees what I'm doing wrong in the attempt to use getElementById(). It's not essential that I find out, however it would improve my program's readability, probably improve the efficiency, and help me understand whatever concept I seem to be missing. I have been all through the javadoc online and I can't seem to figure out what's up with it.

    This is a user error. If it is any consolation, it is not uncommon.
    By "Id" this method looks for the attribute defined in the schema for this kind of XML file as an ID. It may or may not be "id".
    The JavaDoc for this method says:
    Attributes with the name "ID" or "id" are not of type ID unless so defined.
    So, you could have an attribute "programnum" defined as an ID in the schema, and find a value of that attribute with the getElementById() method.
    Dave Patterson

  • Org.w3c.dom.Document toString() ?

    hi i have a constructed org.w3c.dom.Document var newDoc...
    in ibm developerworks tutorial there is a line newDoc.toString() but that gives "[#document null]"
    newDoc.getDocumentElement().getNodeValue() gives the xml string in jdk 1.4 but not in jdk 1.3 wih apache xerces 2.6.2
    how to i get the xml in string output? (i do not wish to use sun java web service development platform)
    please email responses to vishalrao at gmail dot com , thanks!

    From what I saw there was no change and the document getNodeValue always returns null in jdk1.4 as well.
    you can use the transform api to serialize xml into any serialized output form, including strings.
    look into http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/Transformer.html

  • Org.w3c.dom.Document skip a lines between Elements

    Hello,
    I'm generating an XML file from an org.w3c.dom.Document and I'd like to know how can I manually skip a line in the generated xml file.
    <root>
    <myElement>...</myElement>
    skip a line here !
    <myElement>...</myElement>
    </root>
    Thanks,
    Tex

    It's hard to skip half a line, so I don't understand what that last comment means.
    Anyway, with the code you have there your document should end like this:
    <myElement>...</myElement>
    </root>That's because you added a newline as the last child of your root element. If you wanted to add a newline where your original post said you wanted to add a newline, then adding one at the end isn't the right thing to do.

Maybe you are looking for

  • 3Gs not recognized, won't charge after use of aftermarket cord

    My iPhone 3Gs isn't recognized by my windows laptop (I get the "USB device not recognized" error popup and the device doesn't show in iTunes) and will only charge when it is powered off. I have the latest version of iTunes, and I have tried numerous

  • Problem in getting HR data .... in declaring Infotype 9205

    i want to save some HR data using an FM so i am calling FM HR_infotype_operation in my method this require a 4 char infotyp as exporting parameter which I have to declare using INFOTYPES statement inside the method the issue is the environment is not

  • AA close

    We have a scenario where we would want to seperate the last month into 2 periods and would include a 13th period (20 and 10 days). This means depreciation has to run for 20 days and then for 10 days as this would be a seperate period. I would like to

  • Photoshop Elements 13 and RAW files from Canon 7DMII?

    I just received a Canon 7D Mark II and need some editing software that can handle it's RAW images.  I currently use Photoshop Elements 11 and really like it but the version of Camera RAW in that software cannot take the 7DMII files even though I did

  • Workflow in Aperture for Alamy

    As a contributor to Alamy and a new user of Aperture, I wonder if anyone could recommend an ideal workflow. Most importantly the export settings to meet the Alamy specs. I am shooting using a Nikon D80 which gives a RAW file size of about 8.5 MB. Tha