XML : Transform DOM Tree to XML String in an applet since the JRE 1.4.2_05

Hello,
I build a DOM tree in my applet.
Then I transform it to XML String.
But since the JRE 1.4.2_05 it doesn't work.
These lines failed because these variables became final:
org.apache.xalan.serialize.CharInfo.XML_ENTITIES_RESOURCE = getClass().getResource("XMLEntities.res").toString();
org.apache.xalan.processor.TransformerFactoryImpl.XSLT_PROPERTIES = getClass().getResource("XSLTInfo.properties").toString();The rest of the code :
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document domXML = builder.newDocument();
// I build my DOM Tree
StringWriter xmlResult = new StringWriter();
Source source = new DOMSource(domXML);
Result result = new StreamResult(xmlResult);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT,"yes");
xformer.transform(source,result);Is there any other way to get an XML String from a DOM tree in an applet ?
I'm so disappointed to note this big problem.

Does anyone have an idea why I get this error message when try to use transform in an applet?
Thanks...
java.lang.ExceptionInInitializerError
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Unknown Source)
     at org.apache.xalan.serialize.SerializerFactory.getSerializer(Unknown Source)
     at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(Unknown Source)
     at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Unknown Source)
     at matrix.CreateMtrx.SaveDoc(CreateMtrx.java:434)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at thinlet.Thinlet.invokeImpl(Unknown Source)
     at thinlet.Thinlet.invoke(Unknown Source)
     at thinlet.Thinlet.handleMouseEvent(Unknown Source)
     at thinlet.Thinlet.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.RuntimeException: The resource [ XMLEntities.res ] could not load: java.net.MalformedURLException: no protocol: XMLEntities.res
XMLEntities.res      java.net.MalformedURLException: no protocol: XMLEntities.res
     at org.apache.xalan.serialize.CharInfo.<init>(Unknown Source)
     at org.apache.xalan.serialize.SerializerToXML.<clinit>(Unknown Source)
     ... 28 more

Similar Messages

  • How to create XML string for an object matching the result of a marshal?

    I'm trying to create a XML string representation of an object which exactly matches the XML which results from marshalling the object into a request. I'm almost there except that the XML string I come up with is missing the attribute "standalone=\"yes\"" in the topmost xml element, and this attribute is present in the marshalled XML. I'm using the XML string to create a payload signature which must match exactly with the XML payload of the request, so the two XML representations of the object really do need to be identical.
    Here's what I'm doing to create the XML from the object:
       private String myObjectToXmlString (final MyObject myObject)
           throws Exception {
                 try {
               DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
               Document document = documentBuilder.newDocument();
               myObjectMarshaller.marshal(myObject, document);
               Source source = new DOMSource(document);
               StringWriter stringWriter = new StringWriter();
               Result result = new StreamResult(stringWriter);
               TransformerFactory factory = TransformerFactory.newInstance();
               Transformer transformer = factory.newTransformer();
               transformer.transform(source, result);
               return stringWriter.getBuffer().toString();
           } catch (Exception ex) {
               throw new Exception("Unable to convert a MyObject object to an XML String -- " + ex.toString(), ex);
       }The XML which is produced looks like this:
    <?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <ns2:myObject xmlns:ns2=\"http://sunconnection.sun.com/xml\">
       <myObjectId>0</myObjectId>
       <objectType>1</objectType>
       <description>Test Object</description>
    </ns2:myObject>The payload object is marshalled to the request like so:
        // marshall the MyObject to the output stream
       OutputStream outputStream = myHttpUrlConnection.getOutputStream();
       myObjectMarshaller.marshal(myObject, outputStream);
       outputStream.flush();
       outputStream.close();When I view the XML payload of the request it looks like this:
    <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
    <ns2:myObject xmlns:ns2=\"http://sunconnection.sun.com/xml\">
       <myObjectId>0</myObjectId>
       <objectType>1</objectType>
       <description>Test Object</description>
    </ns2:myObject>As you can see the two XML representations of the object are identical except for the standalone attribute in the xml element.
    It'd be a hack to make the assumption that the standalone attribute will always be there in the marshalled object and to just hard code it into the XML string returned by my object to XML method. Since I'm using the same Marshaller to create the XML string as I am to perform the marshalling to the request I assume that there's some way to make it give the same XML in both cases, and that I'm doing something wrong in my method which converts the object to an XML string. If anyone can see where I'm going wrong in that method (myObjectToXmlString() above), or can suggest a better way of doing this, then I'll certainly appreciate the insight.
    --James                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    It turns out that I was taking the wrong approach in my object to XML string method. A cleaner/better way to do it, which gives the correct result, is this:
        private String myObjectToXmlString (final MyObject myObject)
            throws Exception {
            try {
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                myObjectMarshaller.marshal(myObject, stream);
                return stream.toString();
            } catch (Exception ex) {
                throw new Exception("Unable to convert a MyObject object to an XML String -- " + ex.toString(), ex);
        }--James                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Is it possible to pass a string from an applet to the web site?

    Hi, everybody!
    Is it possible to pass a String from an applet to a web site (as a field value in a form, an ASP variable, or anything else). Basically, I have a pretty large String that is being edited by an applet. When a user clicks on the submit button, a different page will show up which has to display the modified string. The String is pretty large so it doesn't fit into the URL variable.
    Please, help!
    Thank you so much!

    Why do you want to do this in Java?
    Javascript is the correct language for these type of situations.
    for instance:
    in the head of your html document:
    <script language=javascript type="text/javascript">
    createWindow(form){
    if(form.text.value!=""){
    newDoc = new document
    newDoc.write(form.text.value)
    newWin = window.open(document,'newWin','width=200;height=150')
    </script>
    in the body:
    <form onSubmit="createWindow(this)">
    <p>
    Enter a String:<input type=text size=30 name="text">
    </p><p>
    <input type=submit value="submit"> 
    <input type=reset value="reset">
    </p>
    </form>

  • Unparsing a DOM tree and write XML to file

    Hi,
    I have created a DOM tree from scratch and would like to unparse the DOM tree and write the XML to a file, but how do I do that?
    Does anybody got code examples that do this?
    All help are very appreciated!
    /Daniel

    Thank you very much for the hint! Unfortunaly I still got problem to get it work though.
    I made a little piece of test code to try it but during the execution of the "Transformer.transform(source,result)" method I gets an "org.w3c.dom.DOMException".
    Does anybody see what that problem might be cause of by exmining the code below?
    I also would like to know how to specify the location where I would like to print out the XML file.
    Here is my little piece of test code:
    try{
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFadctory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    doc.appendChild(doc.createElement("topLevel"));
    Element elm = doc.getDocumentElement();
    elm = (Element)elm.appendChild(doc.createElement("PersonData"));
    elm = (Element)elm.appendChild(doc.createElement("Name"));
    elm.setAttribute("Firstname","D");
    elm.setAttribute("Lastname", "D");
    DOMResult result = new DOMResult(doc);
    DOMSource source = new DOMSource(doc);
    TransformerFactory transformerFactory = TansformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(source,result);
    }catch(ParserConfigurationException e) {
    }catch(IOException e) {
    }catch(TransformerException te) {

  • I want to transform an object into a XML-String

    Hallo,
    in my BSP I want to transform an object into a xml string to set a server side cookie.
    Therefore my code is:
      DATA:
        lv_xml      TYPE string,
        lv_username TYPE string.
    model    ?= get_model( model_id = 'main' ).
      lv_username = sy-uname.
      Call TRANSFORMATION id SOURCE o = model  RESULT XML lv_xml.
      cl_bsp_server_side_cookie=>set_server_cookie(
            name                  = 'MODEL'
            application_name      = runtime->application_name
            application_namespace = runtime->application_namespace
            username              = lv_username
            session_id            = runtime->session_id
            data_value            = lv_xml
            data_name             = 'MODEL'
            expiry_time_rel       = 3600 ).
    But after the command "Call Transformation" the xml-string doesn't contain all the data of my object, only this:
    <?xml version="1.0" encoding="iso-8859-1"?>#<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"><asx:values><O href="#o19"/></asx:values><asx:heap xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:abap="http://www.sap.com/abapxml/types/built-in" xmlns:cls="http://www.sap.com/abapxml/classes/global" xmlns:dic="http://www.sap.com/abapxml/types/dictionary"> <cls:ZCL_M_ESS_TRV_OVW id="o19"/
    ></asx:heap></asx:abap>
    What is wrong?
    Regards.
    Martin

    see thread nr.: Re: Call transformation with an object

  • Getting HTML string out of DOM tree

    after i apply XSL transformation to an XML document, i get a
    DOM tree as a result.
    how do i extract the HTML from that tree as a string? lotus xsl
    lets you pass a PrintWriter to XSLProcessor -- how can I use the
    DocumentFragment for that same thing?
    thank you very much,
    zak.
    null

    zak may (guest) wrote:
    : : At this point we do not support xsl:output so you the only
    way
    : : to get printed output at this point is to use the DOM print
    : : method. xsl:output will be supported in a future release.
    : that's great -- but which "DOM print method" are you reffering
    : to?
    : neither DocumentFragment, nor Document, nor Node have a print
    : method.
    : my question remains -- how do I get at the HTML result of an
    XSL
    : transformation? XSLProcessor.processXSL returns a
    : DocumentFragment -- how do I print that DocumentFragment,
    markup
    : tags and all?
    : thank you very much,
    : zak.
    Both XMLDocument and XMLNode have a variety of print methods.
    None of them will transform XML into HTML however.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • How to parse XML string fetched from the database

    i want to parse the XML string which is fetched from the oracle database.
    i have inserted the string in xml format in the database. The type of the field in which it is inserted is varchart2.
    I am successfully getting it using jdbc, storing it in a String.
    Now it is appended with xml version 1.0 and string is ready for parsing.
    Now i am making following programming.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = Builder.parse(xmlString);
    Element root = doc.getDocumentElement();
    NodeList node = root.getElementsByTagName("product");
    But i am getting IOException at the statement
    Document doc = Builder.parse(xmlString);
    there fore i request u to kindly help me in solving this error.
    -regards
    pujan

    DocumentBuilder does not have a method parse with xml string as aparameter. The string should be a xml document uri.
    Convert xml string to StringReader.
    parse(new InputSource(new StringReader(xmlString)));

  • Serialization of DOM Tree+calling POST method in servlet

    Hi all,
    I am trying to serialize a DOM tree and send it from an applet to a servlet..I am having difficulty in calling the post method of the servlet..can anyone please tell me how the POST method in the servlet is called from the applet...I am using the code as seen on the forum for calling the POST method as below:
    URL url = new URL("http://localhost:8080/3awebapp/updateservlet");
    HttpURLConnection con = (HttpURLConnection)url.openConnection();
    con.setUseCaches(false);
    con.setRequestProperty("Content-Type","application/octet-stream");
    System.out.println("Connected");
    con.setDoOutput(true);
    con.setRequestMethod("POST");
    System.out.println("do output called");
    con.setDoInput(true);
    System.out.println("do Input called");
    ObjectOutputStream objout = new ObjectOutputStream(con.getOutputStream());
    yet the post method in the servlet does not seem to be called....
    another problem I had was trying to serialize a DOM document and send it to the servlet. I am using the following code to write the DOM document on an output stream..would this work:
    OutputFormat format = new OutputFormat(document);
    XMLSerializer serializer = new XMLSerializer( objout, format );
    System.out.println("XML Serializer Started");
    DOMSerializer newSerializer=serializer.asDOMSerializer();
    newSerializer.serialize( document );
    objout.flush();
    objout.close();
    ...since the doPost method of the servlet is not being called I do not whether the above code would be sent to the servlet..
    Any advice on the above two matters would be highly appreciated..
    Fenil

    perhaps my piece of code may help You - relevant parts marked //<--,
    but I have a problem when reading my object - which is a serialized DomTree :
    Variant 1 : sending XML-data as string will arrive as should be, but parser says org.xml.sax.SAXParseException (missing root-element)
    Variant 2 : readObject says java.io.OptionalDataException, but the DomTree will be parsed and displayed
    -- snipp --
    import java.io.InputStream;
    import org.w3c.dom.Document;
    import java.net.*;
    import com.oreilly.servlet.HttpMessage; //<--
    import java.util.*;
    import java.io.ObjectInputStream;
    myApplet :
    try {
         URL url = new URL(getCodeBase(),"../../xml/FetchDocument");
         HttpMessage msg = new HttpMessage(url);
         Properties props = new Properties();
         props.put("InputFeldName","FeldWert");
         InputStream in = msg.sendGetMessage(props);
    //<-- alt : sendPostMessage
         ObjectInputStream result = new ObjectInputStream(in);
         try {
         Object obj = result.readObject();
    myServlet :
    public void doGet(HttpServletRequest req,HttpServletResponse res)
         throws ServletException, IOException {
    TreeCreator currentTree = new TreeCreator();
    ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
    -- variant 1 :
    out.writeObject(currentTree.skillOutputString());
    out.flush();
    out.close();
    -- variant 2 :          
    OutputFormat( TreeCreator.cdi ); //Serialize DOM
    OutputFormat format = new OutputFormat( currentTree.getCDI() ); format.setEncoding("ISO-8859-1");
    XMLSerializer serial = new XMLSerializer( out, format );
    serial.asDOMSerializer(); // As a DOM Serializer
    serial.serialize( currentTree.getCDI().getDocumentElement() );
    serial.endDocument();
    out.flush();
    out.close();

  • XML Parsing Error in applet

    I'm trying to parse a XML dicument in an applet with the following code
    String url = "myfile.xml";
    org.w3c.dom.Document doc = null;
    try
    doc = db.parse(url);
    catch (SAXException se)
    System.out.println("SAX error");
    and get the SAXException when the XML document contains a
    non-ASCII, but ISO-8859-1 character (i.e. '�' = 0xE4)
    Running the same code as Java application on the same computer,
    where I also run the applet, works fine (no exception occurs).
    IMHO, there should not be any difference, both applet and application
    should use the same VM and, hence, the same XML parser.
    Any idea why not?
    I have the Sun VM coming with JRE1.4.0 installed on a PC with
    windows 2000, and also got the same result with JRE1.4.2.
    I checked whether the server application sends the correct xml document
    by printing it to System.out (=java console of the browser, where the applet
    runs, and this seems to be OK. So, my java application seems to be OK.
    Is there any possibility that some settings in the browser cause this problem?
    The longer I think about it, the more I'm confused.
    Thanks in advance for any suggestions!

    the error was set I didn't set the contentLength in the http header when sending the xml file from the servlet.
    I don't really understand why this caused the type of error I experienced, but, at least, my applet works fine now.

  • Schema validation error when validating dom tree in memory

    Hello folks,
    I have the following problem:
    I construct a xml-file via the DOM API and before writing to file, I want to validate the DOM tree against a existing schema file.
    But I always receive following error:
    In line 0 of buffer:
    LSX-00006: No default namespace for "conf_file"
    Validation failed, error 6
    Here's what the xml file looks like:
    <conf_file xmlns="http://www.sun.com/gridware/configuration_file_format" >
    <conf_version>0</conf_version>
    <conf_entry>
    <param>test</param>
    <value>0</value>
    </conf_entry>
    </conf_file>
    The curious thing about that is, when first writing the DOM tree to file via printStream() and then validating the written xml file againstr the schema everything works fine.
    Do you know what I doing wrong ?
    Thanks ...
    Harti

    It is a bug.

  • Help with creating a new XML file from an existing DOM tree!!

    i want to create a new XML file from an existing DOM tree
    i used this code to create a new document:
    static public Document createDocument(String fileName) throws ParserConfigurationException//,IOException,SAXException
              try {
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   factory.setIgnoringComments(true);
                   factory.setIgnoringElementContentWhitespace(true);
                   factory.setValidating(true);
                   DocumentBuilder builder =factory.newDocumentBuilder();
                   return builder.newDocument();
    //          handle exception creating DocumentBuilder
              catch ( ParserConfigurationException parserError ) {
                        throw new ParserConfigurationException();
              }then i used this code to transform the DOM :
    public void exportDocument(Document document) {
              try {
                   Source xmlSource = new DOMSource( document );
                   Result result = new StreamResult( System.out );
                   TransformerFactory transformerFactory =
                        TransformerFactory.newInstance();
                   Transformer transformer =transformerFactory.newTransformer();
                   transformer.setOutputProperty( "indent", "yes" );
                   transformer.transform( xmlSource, result );
           //then catching the exceptions
    But the file was not created and i didn't find where can i specify the DTD that the XML file should use and where can i enter the name of the XML file itself
    Another questoin can i write a DTD file dynamically during the execution of the program??

    Cross-post: http://forum.java.sun.com/thread.jspa?threadID=784467&messageID=4459240#4459240

  • Generate an XML file from a DOM tree

    Hi,
    I'm trying to generate an XML file from a DOM tree that I obtained from another XML file with the Xerces library. I used the following operation :
    public static void writeXmlFile(Document doc, String filename) {
    try {
    Source source = new DOMSource(doc);
    File file = new File(filename);
    Result result = new StreamResult(file);
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.transform(source, result);
    } catch (TransformerConfigurationException e) {
    System.err.println(e);
    System.exit(1);
    } catch (TransformerException e) {
    System.err.println(e);
    System.exit(1);
    But I have this Windows/Linux problem. When I execute this on Windows, everything is correct. But if I try on Linux (every distribution does the same thing), I obtain an XML file where everything is written on just ONE LINE : there is neither identation nor carriage return at the end of a line ... And that is pretty annoying 'cause I need to SEE what I generate ...
    Thanks for your answer,
    Blueberryfin.

    Actually I would think that no indents and no new-lines would be more correct, but maybe it's an option for parsers to do it either way if you don't specify it. If you want to specify it, look at this post from last month:
    http://forum.java.sun.com/thread.jsp?forum=34&thread=383400

  • How can i write the DOM tree to the XML File?

    Asslamo ala mn etb3a Alhoda.
    My problem priefly is that i can't write the DOM tree to XML file.
    I write following code to give the user the ability to input the name of data base which he want to create.
    If i wrote DB name,its atrributes and its values succefully to XML file ,then i'll read it succefully to RAM.
    It'll be simple DBMS.
    ***My code***
    import javax.swing.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.Document;
    import org.w3c.dom.DOMException;
    import org.w3c.dom.Element;
    public class Main {
         * @param args
    public static void main(String[] args) {
         // TODO Auto-generated method stub     
         String DBname;
    DBname=JOptionPane.showInputDialog("Enter Your Data Base Name");
    OPerations O=new OPerations();
         O.creatDB(DBname);
    class OPerations {
    public void creatDB(String name){
         //get an empty Document
         DocumentBuilderFactory f; f=DocumentBuilderFactory.newInstance();
         try {
              builder = f.newDocumentBuilder();
              Document doc= builder.newDocument();
         //Build tree DOM With the root Node
              Element root=doc.createElement(name);
         //add the root element to thevdocument
              doc.appendChild(root);
    catch (ParserConfigurationException e) {
         // TODO Auto-generated catch block
              e.printStackTrace();
    }

    Do an identity transformation to output it:TransformerFactory tf = TransformerFactory.newInstance();
    Transformer tr = tf.newTransformer();
    tr.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(new File(filename))));(typed without syntax check)

  • How i can store a DOM Tree to XML file

    I want to insert a xml documet into another another xml document and then store it.
    for this i have parsed a xml document using com.sun.xml.parser and got its domtree in document doc1 by builder.getDocument(). After that i parsed another xml document and got it's domtree in document doc2 by builder.getDocument().
    now i created a Document type doc . I create dom tree in doc that contains all the nodes of doc1 and insert the doc2 at a position . If i m printing this doc i got the required document. Now i want to store this doc into a xml file. so i paas thid doc and filename in which i want to store it into a function
    public static void writeXmlToFile(String filename, Document document)
    try
                   // Prepare the DOM document for writing
         Source source = new DOMSource(document);
         // Prepare the output file
         File file = new File(filename);
         Result result = new StreamResult(file);
    // Write the DOM document to the file
         // Get Transformer
         Transformer xformer = TransformerFactory.newInstance().newTransformer();
              // Write to a file
         xformer.transform(source, result);
    catch (TransformerConfigurationException e)
         System.out.println("TransformerConfigurationException: " + e);
    catch (TransformerException e)
         System.out.println("TransformerException: " + e);
    but i m getting following error
    Exception in thread "main" java.lang.AbstractMethodError: com.sun.xml.tree.ElementNode.getNamespacesURI()Ljava/lang/String;
    at com.sun.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
    at com.sun.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
    at com.sun.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown Source)
    at com.sun.apache.xalan.internal.xsltc.trax.TranformerImpl.transformIdentity(Unknown Source)
    at com.sun.apache.xalan.internal.xsltc.trax.TranformerImpl.transformIdentity(Unknown Source)
    at com.sun.apache.xalan.internal.xsltc.trax.TranformerImpl.transformIdentity(Unknown Source)

    thanks for the reply
    i m able to do my job using
    import javax.xml.parsers.*;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder1 = factory.newDocumentBuilder();
         doc = builder1.parse(uri);
    when i want to covert this doc into an xml file by passing this doc in the function below then it is ok..
    public static void writeXmlToFile(String filename, Document document)
    try
    // Prepare the DOM document for writing
    Source source = new DOMSource(document);
    // Prepare the output file
    File file = new File(filename);
    Result result = new StreamResult(file);
    // Write the DOM document to the file
    // Get Transformer
    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    // Write to a file
    xformer.transform(source, result);
    catch (TransformerConfigurationException e)
    System.out.println("TransformerConfigurationException: " + e);
    catch (TransformerException e)
    System.out.println("TransformerException: " + e);
    but i want to use com.sun.xml.parser like
    import com.sun.xml.parser.*;
    import com.sun.xml.tree.XmlDocumentBuilder;
    XmlDocumentBuilder builder = new XmlDocumentBuilder();
    Parser parser = new com.sun.xml.parser.Parser();
    parser.setDocumentHandler(builder);
    builder.setParser(parser);
    builder.setDisableNamespaces(false);
    parser.parse(uri);
    doc = builder.getDocument();
    when i m trying to store this doc into an xml file by passing this doc into funtion writeXmlToFile( filename, doc) then the errors occur (that i hav told in the first post)
    plz help..

  • How to convert DOM Tree in XML File

    Hi there,
    I am successful to build a DOM tree in memory where i am adding elements. Now after all this i want to make a XML file of that DOM representation. Now, i am confused with my code that how to transfer DOM structure to xml file ? A small code is attached herewith ?
    doc = db.newDocument();
                   doc.normalizeDocument();
                   doc.setXmlVersion("1.0");
                   doc.createComment("Created By: Sachin Kulkarni");
                   Element rn = doc.createElement("RootNode");
                   Element n1 = doc.createElement("A1");
                   ((Node)n1).setNodeValue("Element A1");
                   Element n11 = doc.createElement("A11");
                   ((Node)n11).setNodeValue("Element A11");
                   Element n12 = doc.createElement("A12");
                   ((Node)n12).setNodeValue("Element A12");
                   ((Node)n1).appendChild( ((Node)n11) );
                   ((Node)n1).appendChild( ((Node)n12) );
                   Element n2 = doc.createElement("A2");
                   ((Node)n2).setNodeValue("Element A2");
                   Element n3 = doc.createElement("A3");
                   ((Node)n3).setNodeValue("Element A3");
                   ((Node)rn).appendChild( ((Node)n1) );
                   ((Node)rn).appendChild( ((Node)n2) );
                   ((Node)rn).appendChild( ((Node)n3) );
    //creating the xml file
                   Source source = new DOMSource((Element) doc.getElementsByTagName("RootNode").item(0));
                   StringWriter out = new StringWriter();
                   StreamResult result = new StreamResult(out);
                   Transformer transformer = TransformerFactory.newInstance().newTransformer();
                   transformer.setOutputProperty("encoding", "iso-8859-1");
                   transformer.setOutputProperty("indent", "yes");
                   //transformer.setOutputProperty("test.xml","1");
                   //transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
                   transformer.transform(source,result);
                   result.getWriter().toString();
    ==================
    Is it any problem with the implementation ? How to use fileoutputstream with this ?

    I have done like this:
    DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = docBuildFactory.newDocumentBuilder();
    Document doc = builder.newDocument();
    Element root = (Element)doc.createElement("Root");
    doc.appendChild(root);
    Element address = (Element)doc.createElement("Address");
    address.appendChild((Element)doc.createElement("Street"));
    address.appendChild((Element)doc.createElement("PostCode"));
    address.appendChild((Element)doc.createElement("Town"));
    Element country = (Element)doc.createElement("Country");
    country.setAttribute("type","EU");
    Text cname = doc.createTextNode("Spain");
    country.appendChild(cname);
    address.appendChild(country);
    root.appendChild(address);
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    Transformer aTransformer = tranFactory.newTransformer();
    aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
    Source src = new DOMSource(doc);
    Result dest = new StreamResult(new FileOutputStream(new File("test.xml")));
    aTransformer.transform(src, dest);

Maybe you are looking for

  • I found a bug? No apps on first page? (or !) (how to reproduce it!)

    Hello dear all, Today I finally found out how to reproduce a bug on my iPhone, which I had already a serval times. The Bug is not worse, it just kinda looks cool. (I will post some links to Screenshots when MobileMe is out of maintainence) _*Well,to

  • Fullview RAW/JPG Images in Aperture appear fractured and/or solid black

    Hey guys, I'm very close to throw something out of the window. I changed from iPhoto to Aperture 3.5.1 a few month ago and imports from my 400D Canon and iPhone/iPad worked finde until recently, when Aperture decided not to show thefull view anymore.

  • My iPhone 4 randomly shut down and won't turn back on.

    My iPhone randomly shut down whenever I got a phone call twice in maybe 5 minutes. Now it wont turn on no matter how many times I plug it in or use the home and lock button. Is there anything I can do? After the first time it just turned back on but

  • Capture the Uploaded by in line item BP

    Hello All, Is it possible to capture the user name in the detail form(Line Item BP) , who uploaded the document in the line item because i see that only Upload By feature is only for Document Attribute form. Regards, Ankit

  • Installing codecs for mpeg-3 on Oracle Linux 6.4

    Hi, I am trying to install the required codecs for mpeg-3 on my Oracle 6.4 Linux box, with no success. I found the discussion from August 2011 Re: How to install media codecs in OL6 U1 on how to do this and have followed the instructions, (I had to s