Creating new xml document

Hi
there are many samples about reading results into xml, but how can the oracle xml parser be used to create a xml document (String) from the scratch?
Thanks a lot for suggestions
Daniel

Thanks , but i know all this !
File corFile = new File("e:\\corFile.xml");
DOMParser dp=new DOMParser();
InputStream is = new FileInputStream(corFile);
XMLDocument root=XMLHelper.parse(is,null);
is.close();
Element hello = root.createElement("hello");
Text bonjour = root.createTextNode("Bonjour");
hello.appendChild(bonjour);
root.appendChild(hello);
i know how i can update the XMLDocument ,
but how i can update my file corFile.xml ??
i would create a new xml file from my new XMLDocument !

Similar Messages

  • ClassCastException while creating an XML document in servlet

    HI,
    I am trying to create an XML document in a servlet and I am getting ClassCastException at runtime when casting org.w3c.dom.document to org.apache.crimson.tree.XmlDocument . I am using Tomcat 4.1
    The same code is working fine when executed in a stand alone java program
    Can anyone please help me in trying to solve this problem. I require it urgently.
    The following is my code:
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.apache.crimson.tree.XmlDocument;
    public class test{
    public void createxml (String username) throws Exception
              Document doc=null;
              DocumentBuilderFactory dbf=null;
         DocumentBuilder db=null;
         Element root=null;
         Element poline=null;
         org.apache.crimson.tree.XmlDocument xmldoc=null;
         FileOutputStream fos=null;
         dbf = DocumentBuilderFactory.newInstance ();
              db = dbf.newDocumentBuilder ();
              doc = db.newDocument ();
              root = doc.createElement ("album");
              doc.appendChild (root);
              poline= doc.createElement("album-name");
              root.appendChild(poline);
    //I am getting the ClassCastException in this statement
              xmldoc = (XmlDocument) doc;
              fos = new java.io.FileOutputStream("xyz.xml");
              xmldoc.write(fos);
              fos.close();
    }

    I am not too much of an expert on this issue, but I did a search. Maybe this page can help or point you in the right direction.
    http://www.jspwiki.org/Wiki.jsp?page=A2AClassCastException
    I hope this helps.

  • Creating an xml document from filenames of selected files

    Hey guys, I am totally new to automator and applescript so please be kind!
    I have an xml/flash image portfolio website which has image galleries. Each gallery has an xml document which specifies a thumbnail and full size photo to be displayed in the gallery. If I want to make a new gallery I have to make a new xml document and enter all the filenames of the images I want to display in the gallery. ( I guess you can see where this is going).
    This is fine if I have 10 images in the gallery but if I want to make a gallery with 350 images in then it could get pretty tedious.
    What I would love to be able to do is select a group of images and then have a script or automator action that can copy the files names and create a new gallery xml document containing the relevant code with all the files names. Ideally then saving the gallery with a sequential filename.
    Tying this into the new contextual services menu in snow leopard would really make the task incredibly easy.
    Is this possible? I'm not scared of learning how to do this therefore some pointers in the right direction would be great.
    Thanks,
    Chris

    Thanks Camalot,
    I was just thinking of selecting images from the finder but if this could be integrated into Aperture's export dialog that would be even better.
    this is the xml:
    <?xml version="1.0" encoding="utf-8"?>
    <gallery thumbwidth="220" thumbheight="138" columns="3" gap="4">
    <item>
    <ID>1</ID>
    <title><![CDATA[Title 1]]></title>
    <desc><![CDATA[This is description 1. <font color="#0099CC">This is a colourful text. </font> This is a <a href="http://www.flashden.net/user/iceonflames">link</a>. <i>This is italic text.</i> <b>This is bold text.</b> <b><i>This is bold italic text.</i></b> This text is styled by a CSS document.<br/><br/>]]></desc>
    <thumb>images/thumbs/7.jpg</thumb>
    <image>images/big/7.jpg</image>
    </item>
    <item>
    <ID>2</ID>
    <thumb>images/thumbs/8.jpg</thumb>
    <image>images/big/8.jpg</image>
    </item>
    <item>
    <ID>3</ID>
    <title><![CDATA[Title 3]]></title>
    <desc><![CDATA[This is description 3. <font color="#0099CC">This is a colourful text. </font> This is a <a href="http://www.flashden.net/user/iceonflames">link</a>. <i>This is italic text.</i> <b>This is bold text.</b> <b><i>This is bold italic text.</i></b> This text is styled by a CSS document.<br/><br/>]]></desc>
    <thumb>images/thumbs/9.jpg</thumb>
    <image>images/big/9.jpg</image>
    </item>
    </gallery>

  • How to create an XML document from a String.

    Can anyone help,
         In the Microsoft XML Document DOM there is a load function load(string) which will create an XML document, but now we are switching to Java and I do not know how to create and XML document from a string, this string �xml document� is passed to my program from a webservice and I need to read several xml elements form it in a web server.
    This string is a well formatted XML document:
    <?xml version="1.0" encoding="UTF-8"?>
    <Countries NumberOfRecords="1" LanguageID="en-us">
         <Country>
              <CountryCode>AU</CountryCode>
              <CountryName>AUSTRALIA</CountryName>
         </Country>
    </Countries>

    Thanks PC!
    I made it work using:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    factory.setIgnoringComments(true); // We want to ignore comments
    // Now use the factory to create a DOM parser
    DocumentBuilder parser = factory.newDocumentBuilder();
    //TransformThisStringBuffer is a string buffer wich contain the 'XML document (String)'
    InputStream in = new ByteArrayInputStream(TransformThisStringBuffer.toString().getBytes());
    // Parse the InputStream and build the document
    Document document = parser.parse(in);
    But which one is faster InputSource or InputStream, were would you put the "new InputSource(new StringReader(yourString))" in the above code?

  • How to create new XML file using retreived XML content by using SAX API?

    hi all,
    * How to create new XML file using retreived XML content by using SAX ?
    * I have tried my level best, but output is coming invalid format, my code is follows,
    XMLFileParser.java class :-
    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.xml.transform.OutputKeys;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.sax.SAXSource;
    import javax.xml.transform.sax.SAXTransformerFactory;
    import javax.xml.transform.sax.TransformerHandler;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.xml.sax.Attributes;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.XMLFilterImpl;
    public class PdfParser extends XMLFilterImpl {
        private TransformerHandler handler;
        Document meta_data;
        private StringWriter meta_data_text = new StringWriter();
        public void startDocument() throws SAXException {
        void startValidation() throws SAXException {
            StreamResult streamResult = new StreamResult(meta_data_text);
            SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            try
                handler = factory.newTransformerHandler();
                Transformer transformer = handler.getTransformer();
                transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                handler.setResult(streamResult);
                handler.startDocument();
            catch (TransformerConfigurationException tce)
                System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
            super.startDocument();
        public void startElement(String namespaceURI, String localName,
                String qualifiedName, Attributes atts) throws SAXException {
            handler.startElement(namespaceURI, localName, qualifiedName, atts);
            super.startElement(namespaceURI, localName, qualifiedName, atts);
        public void characters(char[] text, int start, int length)
                throws SAXException {
            handler.characters(text, start, length);
            super.characters(text, start, length);
        public void endElement(String namespaceURI, String localName,
                String qualifiedName) throws SAXException {
            super.endElement("", localName, qualifiedName);
            handler.endElement("", localName, qualifiedName);
        public void endDocument() throws SAXException {
        void endValidation() throws SAXException {
            handler.endDocument();
            try {
                TransformerFactory transfactory = TransformerFactory.newInstance();
                Transformer trans = transfactory.newTransformer();
                SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
                DOMResult dom_result = new DOMResult();
                trans.transform(sax_source, dom_result);
                meta_data = (Document) dom_result.getNode();
                System.out.println(meta_data_text);
            catch (TransformerConfigurationException tce) {
                System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
            catch (TransformerException te) {
                System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
    } CreateXMLFile.java class :-
    Sax.startDocument();
    Sax.startValidation();
    Sax.startElement("", "pdf", "pdf", new AttributesImpl());
    Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
    String xmp_str = new String(meta_data.getByteArray(),"UTF8");
    char[] xmp_arr = xmp_str.toCharArray();
    Sax.characters(xmp_arr, 0, xmp_arr.length);
    Sax.endElement("", "pdf", "pdf");
    Sax.endValidation();
    Sax.endDocument();
    Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
    class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
    * In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
    is not an XML type text, it just an Normal text Why that ?
    * Please help me what is the problem in my code?
    Cheers,
    JavaImran

    Sax.startDocument();
    Sax.startValidation();
    Sax.startElement("", "pdf", "pdf", new AttributesImpl());
    Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
    String xmp_str = new String(meta_data.getByteArray(),"UTF8");
    char[] xmp_arr = xmp_str.toCharArray();
    Sax.characters(xmp_arr, 0, xmp_arr.length);
    </code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
    <code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
    Sax.endValidation();
    Sax.endDocument();     
    * I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
    * I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
    Thanks,
    JavaImran{code}

  • How to create a XML document

    Hi,
    I am new to XML and don't understand when to use what.
    I have a java.sql.ResultSet and wants do create a XML document.
    When should I use the following methods ?
    - createElement
    - createAttribute
    - createCDATASection
    - createTextNode
    I think I have to create at least a "root" element, right ?
    Should every column in my resultset be an element and its value an attribute ?
    When should I use CDATA and Text ?
    Please explain this to me.
    Regards Uffe

    Hi,
    Use CDATA sections when you know the string will include some funny characters e.g. ?,<,> etc.
    You can decide yourself whether to create an attribute or a separate element.
    e.g. <book isbn="1234">The Spice Girls</book>
    or
    <book>The Spice Girls
    <isbn>1234</isbn>
    </book>
    I do not know about you, but I like the first better, using attributes.
    It is up to individual preference, but it all depends what you intend to do with the data. At the moment, there is little understanding of how to map a/some xml files to a database type relation.
    Many people are trying to force XML documents into relational database schemas, soem use object-oriented databasese.
    Another suggestion is to treat the whole internet as a big web-site.
    Who knows what is the next big decision, I do not think even the experts know! So, what do you think, your thoughts in this are as important as everybody elses.
    best
    kev

  • How to Create an XML document from XSQL servlet which follows a particular DTD struct

    how to Create an XML document from XSQL servlet which follows a particular DTD structure.Could anyone send me a sample code for this.

    You'll need to associate an XSLT transformation with your XSQL page that transforms the canonical result into your DTD-valid format.
    For example, given an XSQL page like:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="rss.xsl" ?>
    <xsql:query max-rows="3" connection="demo" xmlns:xsql="urn:oracle-xsql">
    select title,id,description,url,to_char(timestamp,'Mon DD') timestamp
    from site_entry
    order by id desc
    </xsql:query>and an "rss.xsl" stylesheet that looks like this:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" doctype-system="rss-0.91.dtd"/>
    <xsl:template match="/">
    <xsl:for-each select="ROWSET/ROW">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    <xsl:for-each select="ITEM">
    <item>
    <title><xsl:value-of select="TITLE"/></title>
    <link><xsl:value-of select="URL"/></link>
    <description><xsl:value-of select="DESCRIPTION"/></description>
    </item>
    </xsl:for-each>
    </channel>
    </rss>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>You produce DTD-valid output against the rss-0.91.dtd DTD that looks like:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE rss SYSTEM "rss-0.91.dtd">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>

  • Create new PR document type

    Hi all,
    I have a requirement to create new PR document type and replace existing PR document type.
    What are the pre-requistes for replacing the existing document type?
    How will it impact on business process?

    Create new document type copying existing one but dont delete the existing doc type as it will affect the old PRs.
    To stop usage of existing doc type you can remove its number range assignment so that no new PR will be created using that doc type.
    For new doc type you have to assign number range.
    Assign field selection key.
    If you have used doc type as characteristics in release strategy then maintain new doc type in release startegy.
    Also check whether the new doc type is linked to purchasing doc types such as PO/RFQ/Contract.
    If you have activated version management for PR then maintain new doc type in version management.
    Hope this clears.
    Njoy SAP
    Edited by: ParagMahajan on Jul 27, 2011 9:46 AM

  • Create an XML document from a HTML form???

    Good morning, is it possible to create an XML document from a HTML form
    if yes, can someone tell me how to proceed exactely, I would be very thankful!

    Hi,
    A very simple intro at this link. Apologies for anything unclear.
    http://cswww.essex.ac.uk/TechnicalGroup/TechnicalHelp/xmlCreate.htm
    best
    kev

  • SAX: How to create new XML file using SAX parser

    Hi,
    Please anybody help me to create a XML file using the Packages in the 5.0 pack of java. I have successfully created it reading the tag names and values from database using DOM but can i do this using SAX.
    I am successful to read XML using SAX, now i want to create new XML file for some tags and its values using SAX.
    How can i do this ?
    Sachin Kulkarni

    SAX is a parser, not a generator.Well,
    you can use it to create an XML file too. And it will take care of proper encoding, thus being much superior to a normal textwriter:
    See the following code snippet (out is a OutputStream):
    PrintWriter pw = new PrintWriter(out);
          StreamResult streamResult = new StreamResult(pw);
          SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
          //      SAX2.0 ContentHandler.
          TransformerHandler hd = tf.newTransformerHandler();
          Transformer serializer = hd.getTransformer();
          serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");//
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"pdfBookmarks.xsd");
          serializer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"http://schema.inplus.de/pdf/1.0");
          serializer.setOutputProperty(OutputKeys.METHOD,"xml");
          serializer.setOutputProperty(OutputKeys.INDENT, "yes");
          hd.setResult(streamResult);
          hd.startDocument();
          //Get a processing instruction
          hd.processingInstruction("xml-stylesheet","type=\"text/xsl\" href=\"mystyle.xsl\"");
          AttributesImpl atts = new AttributesImpl();
          atts.addAttribute("", "", "someattribute", "CDATA", "test");
          atts.addAttribute("", "", "moreattributes", "CDATA", "test2");
           hd.startElement("", "", "MyTag", atts);
    String curTitle = "Something inside a tag";
              hd.characters(curTitle.toCharArray(), 0, curTitle.length());
        hd.endElement("", "", "MyTag");
          hd.endDocument();
    You are responsible for proper nesting. SAX takes care of encoding.
    Hth
    ;-) stw

  • Creating New XML using xPath

    Hi,
    I wanted to know if an XML Document created in the Database using xPaths. I mean, I don't want to creat any XML file on the OS in the first place. I want to create an XML using a table containing xPaths. Can this be done in XDB ?
    Thanks in Advance,
    Piyush

    Hi Piyush
    I don't see how you can create a XML document via xpath!?!? xpath it's only used to reference data in an XML document...
    Chris

  • How to filter xml using dtd and create a new xml document

    Good morning my name is Antonio and I'm an italian programmer.
    I need an help about the follow question.
    I want to filter the contents of a XML document using a DTD to allow
    only the valid elements and attributes as specified in the DTD to be
    passed through to the output, any data that does not conform to the DTD
    should be filtered out.
    To resolve this problem there's XML Translator Generator (XTransGen): http://www.alphaworks.ibm.com/tech/xmltranslatorgenerator
    but at moment it's not avaiable.
    Can you help me?
    Many thanks.
    ciao
    Antonio

    ...

  • Creating an XML document from a DTD in Java

    Hi All,
    I need help on the following requirement very badly. Pls help me.
    I have a requirement to implement with java and XML. I am quit new to XML.Can any of you pls help me.
    I have a DTD file. I need to generate XML document from it using java code. I have to use DTD as a template to generate my XML document.
    After going through WEB sites, I understtod that, we have to user Java API JAXB for my requirement. But I could not find JAXB.jar anywhere.
    I need to know the following inforamtion ....
    1. Is my understanding of using JAXB for my requirement is correct?
    2. Where can I get JAXB.jar?
    3. What are the steps to create XML document from a DTD in Java?
    If can give me a sample code for this would help me a lot.
    Pls pls reply me. Your help is greatly appreciated.
    Thanks in Advance.
    Regards,
    Gayathri.

    hi Gayathri,
    iam currently working in the same field.
    firs download jaxb from this link:
    http://java.sun.com/xml/downloads/jaxb.html
    first u need to marshall it.
    cheers
    shashi

  • BO 4.0: cannot create new WebI document as admin

    Hi,
    I am logged in on our BO 4.0 server as administrator and would like to create a sample WebI report. So I started WebI from the Launchpad but the "create new document" icon is inactive...
    I do have full access and I am using the administrator login... what's missing?
    Thanks!

    Hi Steve,
    Have you tried from another client/browser computer using the same account?
    How about using the rich client? Can you create documents and save them to the repository?
    Regards,
    Julian

  • How to use java to create an XML document from an SQL database?

    Hi,
    I'm a complete novice at XML and have only recently started programming in Java.
    I'm currently trying to develop a package in Java 1.1.8 which requires a set of very specifically formatted XML documents. These documents would need to be updated regularly by people with no knowledge of Java and I would like to make it as simple as possible.
    Since the data will already be in an SQL database, I thought it might be possible to generate the XML documents from the data using a small Java application, but I'm not too sure how to go about this or if this is even possible! Any help or pointers in the right direction would be very much appreciated.
    Louise

    Do you have the option of upgrading to a newer version of the JDK?
    JAXB does what you are wanting very easily. Also there are tools if you don't want to write your own. JAXB is available as early release on Sun's site as is the newest JDK. Otherwise, you have to design a factory and interface that will do this for you (which is what JAXB basically is in a very simplified view).

Maybe you are looking for

  • Using SQL view object to create ADF table

    Hi, I have created a column called "Month" (which extracts month from the date column) and another column to count the no. of requests. i want to create an ADF table with 2 columns, a column showing the month and another is showing the no. of request

  • Helvetica font for (Window) Adobe Creative Suite 6 Master Collection

    A month ago I bought Adobe Creative Suite 6 Master Collection software for Window...... noticed there is no "Helvetica" font in my window program?? How can I add "Helvetica" font into my window software program??? Hope you can help..thanks Steve

  • [SOLVED]Flashplugin causing all browsers to either crash

    Hi guys, i recently installed arch on old machine i was given. after some initial problems with the radeon driver and x11, i now have openbox up and running. as this is an old machine, with only 512mb of ram i've tried using low-overhead browsers at

  • Desk mount articulating arm 24" Imac

    I am trying to find a zero footprint mount for my 24" Imac. All I find does not seem to be able to hold the weight. I can't wall mount due to location. I've spent hours online but can not find what I'm looking for.

  • Nokia 6700 default applications

    Since updating my 6700 classic phone to firmware V07.60 my default applications have stopped working.  All I get is a message saying "Supportive File.  Nothing to display". I have tried resetting the phone and reinstalling the firmware but I still ge