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).

Similar Messages

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

  • 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

  • Create single XML document from multiple queries

    hi all!
    being a new programmer in XML world,my question might sound a bit stupid but your answers would mean a world to me. i have to generate a single XML document from my database by querying more than one table. for example i have 3 tables i.e HR_EMP_NAME, HR_PRODUCTS_DETAIL, HR_PAYROLL_SUMMARY. all three tables have completely different columns except one ID column which is a foreign kay from HR_MASTER_LIST. i want to get any insert operation on these tables as a single document. so far as i have studied, one option is to generate XMLDoc using XSU and then add child nodes using JAXP but i am ot geting the logic right.
    please do reply.
    thanks a lot
    usman

    This is an SQL/XML based answer so how much it helps you is hard to say, but it would be one option. You can have the SQL statement build the XML for you as shown by this simple example.
    SELECT XMLElement("root",
              XMLForest(emp.dummy AS "emp_name",
                        prod.dummy AS "prod_lvl",
                        pay.dummy AS "pay_scale"))
      FROM dual emp,
           dual prod,
           dual pay
    WHERE emp.dummy = prod.dummy
      AND emp.dummy = pay.dummy;which produces (formatted for human readability)
    <root>
      <emp_name>X</emp_name>
      <prod_lvl>X</prod_lvl>
      <pay_scale>X</pay_scale>
    </root>Whether that works with what you are trying to do via Java you will have to decide.

  • Creating an XML file from multiple sql tables

    I have very little xml experience, but need to generate an xml file from multiple table. I know what the output needs to look like, but do not know how to setup the code. Any help would be appreciated.
    - <Practice SourceID="EPIC" ExternalPracticeID="PPAWB">
    - <Provider ExternalProviderID="TB2" FirstName="THOMAS G" LastName="BREWSTER">
    - <Patient ExternalPatientID="99999" OldExternalPatID="" FirstName="test" MiddleName="J" LastName="test" Gender="M" DateOfBirth="2005-08-12" SocSecNumber="000-00-0000" LanguageID="22" AddressOne="test" AddressTwo="" City="test" StateID="20" ZipCode="99999" DayPhone="" EveningPhone="207-999-9999" StatusID="">
    <Measure MeasureID="2" MeasureValue="5" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="2" MeasureValue="5" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="3" MeasureValue="1" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="3" MeasureValue="1" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="32" MeasureValue="3" MeasureDate="2008-10-24 13:51:00" />
    <Measure MeasureID="33" MeasureValue="1" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="33" MeasureValue="1" MeasureDate="2009-02-09 10:09:00" />
    <Measure MeasureID="4" MeasureValue="5" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="4" MeasureValue="5" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="40" MeasureValue="2008-10-24 13:43:00" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="40" MeasureValue="2008-10-24 14:23:00" MeasureDate="2008-10-24 14:23:00" />
    <Measure MeasureID="41" MeasureValue="2008-10-24 13:43:00" MeasureDate="2008-10-24 13:43:00" />
    <Measure MeasureID="41" MeasureValue="2008-10-24 13:51:00" MeasureDate="2008-10-24 13:51:00" />
    </Patient>
    </Provider>
    </Practice>

    You are interested in XMLElement and probably XMLAgg. Since you didn't list a version, I can't provide links to the corresponding documentation. I cringe at all the attributes on the Patient element as that info should really be elements.
    To create the Measure node, your overall SQL statement may look something like (not tested)
    SELECT XMLElement....
              XMLAgg(SELECT XMLElement
                       FROM measures_table
                      WHERE join condition to parent)
      FROM patient,
           provider,
           practice
    WHERE join conditionsFor additional help, please include your version (4 digits), some sample data, and what you have tried.

  • 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 use java to create a windwos service

    install a java program to windwos service and can start or stop it in service.

    I personally have not tried it but this link may be of interest
    [url http://wrapper.tanukisoftware.org/doc/english/index.html]Run as a Windows Service or UNIX Daemon

  • How can I create a XML document from a DOM?

    Hello,
    I'm using the parser for C, version 2 in the DOM modus. How can I dump the object model to a (XML) string after changing some field?
    Do I need to create my own function or is there a function in the DOM interface??

    You need to create your own function. The Java XML parser has such a function
    and we'll probably add one in a future release as well.
    Oracle XML Team

  • How to use Java classes to make any query from Ldap? (any sample)

    Where to find at least a brief description?
    I need links,samples
    Thanks in advance.

    Have a look at the JNDI tutorial: http://java.sun.com/products/jndi/tutorial/index.html

  • Creating PDF documents from PL/SQL

    I would like to know if there is a way to create dynamic PDF documents from PL/SQL procedures using OWA replacement cartridge?
    null

    I would like to know if there is a way to create dynamic PDF documents from PL/SQL procedures using OWA replacement cartridge?
    null

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • How to make a bean create an xml file..

    How does one create an xml file from a bean?
    If anyone have the answer, or some sample code I would really apprecciate it!!!
    In advance thanx a lot!!!

    just "wrap" this up in a bean.
    import java.io.*;
    import org.jdom.*;
    import org.jdom.output.*;
    /** Make up and write an XML document, using JDOM
    * @author Ian Darwin, [email protected]
    * @version $Id: DocWriteJDOM.java,v 1.2 2001/11/21 23:08:17 ian Exp $
    public class DocWriteJDOM {
         public static void main(String[] av) throws Exception {
              DocWriteJDOM dw = new DocWriteJDOM();
              Document doc = dw.makeDoc();
              // Create an output formatter, and have it write the doc.
              new XMLOutputter().output(doc, System.out);
         /** Generate the XML document */
         protected Document makeDoc() throws Exception {
                   Document doc = new Document(new Element("Poem"));
                   doc.getRootElement().
                        addContent(new Element("Stanza").
                             addContent(new Element("Line").
                                       setText("Once, upon a midnight dreary")).
                             addContent(new Element("Line").
                                       setText("While I pondered, weak and weary")));
                   return doc;

  • 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

Maybe you are looking for

  • Sun One Studio Mobile Edition

    I need to add "package Projects.MyProject.Files;" in order for the project to compile and the debugger to work correctly. When I do add the package declaration in the java source code, my midlet suite fails to compile and execute. How can I correct t

  • Output in Diagramatic Format

    Hi all.. Is there any standard program which displays the output in digramatic / flow chart format ? Regards, K.Tharani.

  • How to locate the repository table relevant to my custom report. ?

    Hi I have to develop custom user  report  in  SAP GTS. User wants custom report with product, classification and tariff details. Please tell me, How do I locate the relevant  table and field from the the GTS SAP repository ? BTW, Where do I go from h

  • SharePoint 2010 - Content database contains orphaned items

    Good day people! We have come across the feared "Content databases contain orphaned items"! Running a check on our farm shows: PS C:\Users\SPAdmin> Get-SPContentDatabase | ForEach-Object { $_.repair($false)} <OrphanedObjects Count="0" /> <OrphanedObj

  • Latest IBM JDK version supported by SAP

    Hi there, we are having some Java performance issues in our landscape and the recommendation from SAP is to install the latest IBM JDK release supported by SAP, can you help me determine what the latest release is and where I can find the download? T