How to use XML / XPath in JAVA (in 1.4) which third part component to use?

How to use XML / XPath in JAVA (in 1.4)
I'm absolutely novice in XML
but I need to query XML using XPath
As I understand XPath become avalible only in Java 1.5
But I use 1.4 (project requirement)
Which third part component could you recomend?

Can anyone help me with this XPath query
I get result [title: null]
import java.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import org.jaxen.*;
import org.jaxen.dom.*;
import org.jaxen.saxpath.*;
import java.util.*;
public class TestX {
     public void ggg() {
          try {
               File f = new File("journal.xml");
               DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
               org.w3c.dom.Document doc = docBuilder.parse(f);
               XPath xpath = new DOMXPath( "/journal/article/title" );
               List result = (List) xpath.evaluate(doc);
               System.out.println(result.get(0));
          } catch (Exception e) {
                   e.printStackTrace();
     public static void main(String[] args) {
          TestX tx = new TestX();
          tx.ggg();
}journal.xml
<journal>
    <article id="article.1">
        <title>Art1</title>
        <author>
           <first>Bob</first>
           <last>McWhirter</last>
        </author>
        <text>
        </text>
    </article>
    <article id="article.2">
        <title>Art2</title>
        <author>
           <first>James</first>
           <last>Strachan</last>
        </author>
        <text>
        </text>
    </article>
</journal>

Similar Messages

  • How many web.xml in a java application

    Hi,
    can anyone give tell the answer for this question "How many web.xml in a java application?"

    1Why ?Because the Web container refers to only one web.xml for one web application.
    I havent heard of an application having more than 1 web.xml
    How?It reads all the definitions of servlet mappings, filters, welcome-file etc from this file itself.
    Where?From the following folder ...
    /WEB-INF
    By the way ..... the way you questioned me was amuzing ... Why? How ?Where ? Its funny :D
    I actually wanted to reply as below ..
    Why ?Why not
    How?
    Wait lemme think ....ummm... What do you mean how??
    Where ?
    Inside the web ;-)
    -Rohit

  • CrystalReports Subreports Demo Using XML As DataSource , Java As Tool

    Hello,
        Im New to CrystalReports.Can any one send me (or) explain me Regarding "CrystalReports Subreports Demo Using XML As DataSource , Java As Tool" .
    Thanks,
    RadhaKrishna K

    ok

  • How to use " toFront() " method in java application and in which package or

    How to use " toFront() " method in java application and in which package or class having this toFront() method.if anybody know pl. send example.

    The API documentation has a link at the top of every page that says "Index". If you follow that and look for toFront(), you will find it exists in java.awt.Window and javax.swing.JInternalFrame.
    To use it in a Java application, create an object x of either of those two classes and write "x.toFront();".

  • Equivalent of SQL JOINs using XML + XPath

    I have been working on a Java app for a while that takes user queries and searches various translations of the Bible. The data is stored in 66 .xml files, one per book of the Bible, and those files, in turn, are stored in a .jar file.
    The user may select 2 or more translations and see them in parallel. So for example, let's say that want Matthew chapter 1 and verses 1 to 10 from KJV and ASV. I simply use the following XPath expression: /book/chapter[@num=1]/verse[@num>=1 and @num<=10] . Then I use XPathFactory, XPath, compile() and evaluate() on Matthew.xml from kjv.jar and asv.jar.
    However, the problem is not so simple for keyword queries from the user. In such a case the tool searches for keywords in one translation and then finds the same verses from all subsequent translations. Here the XPath expression might be more like: /book/chapter/verse[contains(., 'keyword1') and contains(., 'keyword2')] for the first translation. However, if I ran the same query on subsequent translations they may or may not return the exact same set of verses (depending on language (English, Greek, Hebrew) and also on the dialect (Old English vs. Modern English)). So, my question is what is the most efficient way of obtaining the same verses from subsequent translations?
    I could simply look up the verses in the first translation, then use DOM API calls to find the chapter and verse numbers, and look those up in the other translations. But this seems tedious, SLOW, and possibly more error prone.
    Also, a second question: if I wanted to include a help file in my application's .jar file. How could I access that file programmatically? That is, how do I tell the application to look for "help.html" in the jar file so I can manipulate and/or display the contents to the user?
    And last question: since, I'm still learning my way around Java and XML, how would I go about programmatically applying a .xsl file to some given .xml input to produce HTML + CSS output? What classes, interfaces, etc. should I look up for this? And can anyone point me to sample code online for this?

    However, the problem is not so simple for keyword
    queries from the user. In such a case the tool
    searches for keywords in one translation and then
    finds the same verses from all subsequent
    translations. Here the XPath expression might be
    more like: /book/chapter/verse[contains(.,
    'keyword1') and contains(., 'keyword2')] for the
    first translation. However, if I ran the same query
    on subsequent translations they may or may not return
    the exact same set of verses (depending on language
    (English, Greek, Hebrew) and also on the dialect (Old
    English vs. Modern English)). So, my question is
    what is the most efficient way of obtaining the same
    verses from subsequent translations?
    I could simply look up the verses in the first
    translation, then use DOM API calls to find the
    chapter and verse numbers, and look those up in the
    other translations. But this seems tedious, SLOW,
    and possibly more error prone.There's nothing in XPath that I know of that helps with this. SQL is relational, XML is hierarchical. They're fundamentally different.
    Also, a second question: if I wanted to include a
    help file in my application's .jar file. How could I
    access that file programmatically? That is, how do I
    tell the application to look for "help.html" in the
    jar file so I can manipulate and/or display the
    contents to the user?If it's an HTML file, it's likely that you'll package it in a WAR file, along with the rest of your app. It's accessible as a URL that way.
    And last question: since, I'm still learning my way
    around Java and XML, how would I go about
    programmatically applying a .xsl file to some given
    .xml input to produce HTML + CSS output? What
    classes, interfaces, etc. should I look up for this?.xsl transformations are applied using XSL-T engines, like Apache's Xalan. You would embed the HTML that you want to inject the XML data into in the XSL-T stylesheet.
    That's one way. Another is to use a templating alternative like Velocity.
    And can anyone point me to sample code online for this?Try the Apache Xalan docs. Or this:
    http://www.cafeconleche.org/books/xmljava/chapters/ch17.html
    %

  • Help: Using XML to format Java output

    I built an application that uses an SQL DB (uses HSQLDB). Users are prompted to enter data via the keyboard to store in the tables.
    The users must be able to query the database as well, to see what is in the tables.
    My aim is to use XML to show the results of the query, so that it is formatted nicely.
    However, I am new to this and not sure how to start putting in the XML tags etc. I think I know which part of the code to modify. This is the part that does the displaying.
          * Ouptut the contents of a recordset to the console with
          * the column names from the tables
          * @param rs the ResultSet to display
         public static void print(ResultSet rs) throws SQLException {
              ResultSetMetaData meta   = rs.getMetaData();
                 int               colmax = meta.getColumnCount();
                 int               i;
                 Object            o       = null;
              String coln            = meta.getColumnName(1);     
                 for (;rs.next();) {
                     for (i = 0; i < colmax; ++i) {
                    o = rs.getObject(i + 1);// Is SQL the first column is indexed
              coln = meta.getColumnName(i+1);                  
                                                // with 1 not 0
              System.out.println(coln +":"+'\t'+ o.toString() + " ");
                System.out.println(" ");
    }Can anyone give me any guidance or just a hint for me to start?
    Thank you very much.

    Using DOM would probably be the easiest solution, though not fast enough for your problem, as many records might come out of the RS...
    So if performance is an issue, try producing XML with SAX (read the excellent Dr.Clap tips here: http://forum.java.sun.com/thread.jsp?forum=34&thread=326617)
    Else use DOM: chapter 7 here: http://java.sun.com/webservices/docs/1.1/tutorial/doc/index.html

  • How to Query XML Xpath?

    Hi!
    I am new XML as datasource.
    I am using XML in iReport.
    Below is my XML Datasource.
    <?xml version="1.0" encoding="UTF-8"?>
    <MyReport>
         <EvalData>
              <Quarter>
                   <no>Q3'06</no>
                   <EvalValue>2.4</EvalValue>
              </Quarter>
              <Quarter>
                   <no>Q4'06</no>
                   <EvalValue>3.6</EvalValue>
              </Quarter>
              <Quarter>
                   <no>Q1'07</no>
                   <EvalValue>3.7</EvalValue>
              </Quarter>
         </EvalData>
         <QHighLight>
              <Header hdrText="Created IC Calculates and rolled out to field">
                   <subHeader>We are posting personalized IC Calculators every month.</subHeader>
              </Header>
              <Header hdrTest="Cteated SA(Sales Analysis) Reports and rolled out to field managers">
                   <subHeader>We are posting SA Reports every month.</subHeader>     
              </Header>
              <Header hdrTest="Created Personalized web homepages with all current and revelant IC documents">
                   <subHeader>Created personalized Viewer homepages where the reps get links.</subHeader>
              </Header>
              <Header hrdtest="Reduced the proceeeing time for monthly processing">
                   <subHeader>Completing the non-payout month processing in just one week.</subHeader>
              </Header>
         </QHighLight>
         <OutlookNQ>
              <Header>1-Create new IC Calculator Summary report and deliver the same in non payout month</Header>
              <Header>2-Deliver Budget Management and Plan Effectiveness Reports concurrent with the Payroll report.</Header>
         </OutlookNQ>
         <SynygyCI>
              <Name>Schering-Plough</Name>
              <Title>Healthcare Products</Title>
              <Phone_Number>610-494-3300x2129</Phone_Number>
              <Email_Add>[email protected]</Email_Add>
              <Name>Divid Grossberg</Name>
              <Title>Managing Consultant</Title>
              <Phone_Number>610-494-3300x(7045)</Phone_Number>
              <Email_Add>[email protected]</Email_Add>
              <Name>Peter Lamb</Name>
              <Title>Managing Direntor</Title>
              <Phone_Number>610-494-3300x(7656)</Phone_Number>
              <Email_Add>[email protected]</Email_Add>
         </SynygyCI>
         <ccur>
              <quarter no="1">
                   <Credit>210 </Credit>
                   <TC>180</TC>
              </quarter>
              <quarter no="2">
                   <Credit>190 </Credit>
                   <TC>160</TC>
              </quarter>
              <quarter no="3">
                   <Credit>175 </Credit>
                   <TC>155</TC>
              </quarter>
         </ccur>
    </MyReport>The problem is that i just get the first value of the node.
    And not all value.
    So the Report I am tying to create is always has only one value.
    This is query string I am using " //MyReport/* ".
    Thanks for your help in advance.

    It sounds to me as if you have some code somewhere that has the problem you described. Since I can't see any of that code, all I can advise is that you look at it and fix it.
    Or you could post it here. That might have been more useful than all that XML.

  • What is the best third part converter to use with my IPad2 in order to import my videos from my PC?

    I have 70 videos I use in my work and want to import them into my IPad2.  What is the best third party converter to use?

    There is Handbrake (http://handbrake.fr) - aren't the videos compatible with iTunes on your computer, if they are then you can always do Advanced > Create iPad Version if they don't currently sync to the iPad. There are also a number of third-party iPad apps that support other video formats

  • Using XML file in Java script to create Google Map

    Hello,
    I work for a non-profit in San Diego as a GIS Specialist. I have had to teach myself about some scripting to create some dynamic maps, but I am still very limited in my skills, so I have had to explore the internet in order to discover various tutorials and examples that have led me on a positive path.
    Right now I am working on a Google Mash-Up that will incorporate over 14,000 records, which will appear as separate markers that will have pop-up info bubbles with additional info inside (using html), once the marker is clicked.
    Here is the XML script example that is used in the tutorial I am following:
    <markers>
    <marker lat="43.65654" lng="-79.90138" html="Some stuff to display in the<br>First Info Window"
    label="Marker One" />
    <marker lat="43.91892" lng="-78.89231" html="Some stuff to display in the<br>Second Info Window"
    label="Marker Two" />
    <marker lat="43.82589" lng="-79.10040" html="Some stuff to display in the<br>Third Info Window"
    label="Marker Three" />
    </markers>
    ...and this is how it looks when the file is retrieved by the java script and mapped: http://econym.googlepages.com/example_map3.htm
    This is the java script that creates the Google Map. I have emboldened the section of the script that retrieves the data and parses it to create the markers:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Google Maps</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA6GoL8P5zqjQlG5A5uM1ETBSUPozAscB0cY3RG8xEGnZyeom4axRySak889rVpvHYRsV4f9OZZzbboA"
    type="text/javascript"></script>
    </head>
    <body onunload="GUnload()">
    <!-- you can use tables or divs for the overall layout -->
    <table border=1>
    <tr>
    <td>
    <div id="map" style="width: 800px; height: 1200px"></div>
    </td>
    <td width = 200 valign="top" style="text-decoration: underline; color: #4444ff;">
    <div id="side_bar"></div>
    </td>
    </tr>
    </table>
    <noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b>
    However, it seems JavaScript is either disabled or not supported by your browser.
    To view Google Maps, enable JavaScript by changing your browser options, and then
    try again.
    </noscript>
    <script type="text/javascript">
    //<![CDATA[
    if (GBrowserIsCompatible()) {
    // this variable will collect the html which will eventualkly be placed in the side_bar
    var side_bar_html = "";
    // arrays to hold copies of the markers used by the side_bar
    // because the function closure trick doesnt work there
    var gmarkers = [];
    var i = 0;
    // A function to create the marker and set up the event window
    function createMarker(point,name,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
    // save the info we need to use later for the side_bar
    gmarkers[i] = marker;
    // add a line to the side_bar html
    side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
    i++;
    return marker;
    // This function picks up the click and opens the corresponding info window
    function myclick(i) {
    GEvent.trigger(gmarkers, "click");
    // create the map
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng( 37.251699,-119.604315), 7);
    *// Read the data from testXML2blackpoolformat.xml*
    var request = GXmlHttp.create();
    request.open("GET", "testXML2blackpoolformat.xml", true);
    *request.onreadystatechange = function() {*
    *if (request.readyState == 4) {*
    var xmlDoc = GXml.parse(request.responseText);
    *// obtain the array of markers and loop through it*
    var markers = xmlDoc.documentElement.getElementsByTagName("ConnectoryRecord");
    *for (var i = 0; i < markers.length; i++) {*
    *// obtain the attribues of each marker*
    *var lat = parseFloat(markers[i].getAttribute("lat"));*
    *var lng = parseFloat(markers[i].getAttribute("lng"));*
    var point = new GLatLng(lat,lng);
    *var html = markers[i].getAttribute("html");*
    *var label = markers[i].getAttribute("label");*
    *// create the marker*
    var marker = createMarker(point,label,html);
    map.addOverlay(marker);
    // put the assembled side_bar_html contents into the side_bar div
    document.getElementById("side_bar").innerHTML = side_bar_html;
    request.send(null);
    else {
    alert("Sorry, the Google Maps API is not compatible with this browser");
    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/
    // http://econym.googlepages.com/index.htm
    //]]>
    </script>
    </body>
    </html>
    Here is my delima--
    This is the xml format that I need to use because it can accept the rest of my excel file and loop it through the 14,000+ records to create a functioning xml file. This is just a sample (2 records) of the larger file:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <ConnectoryAug2008>
    <ConnectoryRecord>
         <lng>-117.03683</lng>
         <lat>32.944505</lat>
         <ConnectoryID>1</ConnectoryID>
         <Name>$2.95 Guys</Name>
         <StreetAddress>13750 Stowe Drive</StreetAddress>
         <City>Poway</City>
         <State>CA</State>
         <Zip>92064</Zip>
    <Marker>White</Marker>
         <IndustryGroup>Technical Services</IndustryGroup>
         <ConnectoryProfileLink>http://connectory.com/search/profile_view.aspx?connectoryId=1</ConnectoryProfileLink>
    </ConnectoryRecord>
    <ConnectoryRecord>
         <lng>-117.272843</lng>
         <lat>33.13337</lat>
         <ConnectoryID>2</ConnectoryID>
         <Name>(GLDS) Great Lakes Data Systems</Name>
         <StreetAddress>5954 Priestly Drive</StreetAddress>
         <City>Carlsbad</City>
         <State>CA</State>
         <Zip>92008</Zip>
    <Marker>Orange</Marker>
         <IndustryGroup>Technology</IndustryGroup>
         <ConnectoryProfileLink>http://connectory.com/search/profile_view.aspx?connectoryId=2</ConnectoryProfileLink>
    </ConnectoryRecord>
    </ConnectoryAug2008>
    This is the tutorial where I found the formatting techniques to successfully create the large xml file that will format/convert my excel file properly: http://www.mrexcel.com/tip064.shtml
    These variables should appear as html in the info bubble:
    <ConnectoryID>2</ConnectoryID>
         <Name>(GLDS) Great Lakes Data Systems</Name>
         <StreetAddress>5954 Priestly Drive</StreetAddress>
         <City>Carlsbad</City>
         <State>CA</State>
         <Zip>92008</Zip>
    <IndustryGroup>Technology</IndustryGroup>
         <ConnectoryProfileLink>http://connectory.com/search/profile_view.aspx?connectoryId=2</ConnectoryProfileLink>
    The "Marker" variable instructs Google Maps to label the marker with a particular color. I will be so grateful to the person(s) that helps me get through this wall that I have been hitting for a long time. It's very difficult without having the luxury of peers who know about these types of issues.
    Thank you!!

    Here is the relationship: They both contain geographic coordinates that produce a point on a map. I will use the rest of the information in the second xml file (company name, address, link, etc.) to produce the information for the bubble that will pop up once the marker is clicked.
    My problem is that I need to try to keep the second xml file in a relatively similar format, so the rest of my records will still be accepted. If I had a smaller amount of records I could place them directly into the javascript, but because there are so many records, I need to use an xml file that can be retrieved by the java script. I chose to use the second type of xml file because I can easily copy and past the 14,000+ records that are now in excel document.
    After the xml issue is corrected I need to rework the javascript that is now emboldened so that it will read the new xml file correctly. I included the first xml file so that the readers will understand what type of xml format is currently being used to produce the markers in the tutorial map.

  • How to read XML files from java

    i need a sugession that how to read a xml file using java code
    and i need to parse using some parsers and display attributes and entity seperately
    as a string.......

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    import java.io.File;
    import java.text.AttributedCharacterIterator.Attribute;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class XmlParser
    private String Result="";
    private String Final="";
    private String Delim="";
    public void bar1(Document document) throws DocumentException
    org.dom4j.Element root = document.getRootElement();
    // System.out.println(root.getName());
    bar2(root);
    System.out.println(this.Result);
    process();
    public void bar2(org.dom4j.Element e)
    for(Iterator i = e.elementIterator();i.hasNext();)
    org.dom4j.Element Element = (org.dom4j.Element) i.next();
    Result += Element.getName()+"\t"+Element.getText()+"\n";
    bar2(Element);
    public void process()
    StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
    String element;
    while(Tokenizer.hasMoreTokens())
    element = Tokenizer.nextToken();
    StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
    // Do what ever String Process here Example
    this.Final += element.getName();
    this.Final += this.Delim;
    System.out.println(this.Final);
    public static void main(String s[])throws Exception
    Document document = null;
    SAXReader reader = new SAXReader();
    File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
    document = reader.read(f1);
    Demo obj = new Demo();
    obj.bar1(document);
    i think this will hep full.......

  • Using XML parser in Java

    Hi,
    I would like to distribute the Java XML parser with my product (which does not include an Oracle database).
    Do you have an idea, if this can be done ?
    The license agreement is "for a single developer". My local reseller has no clue if I can use for free, or how much does it cost.
    Any idea ?

    Free runtime redistribution. visit the latest download page for the production version to see the verbage.

  • Using xml file in java application

    How can i get the attribute name & value into my java application from a xml flie?

    read the file
    parse the contents
    store attribute name & value pairs.
    %

  • How to parse xml data into java component

    hi
    everybody.
    i am new with XML, and i am trying to parse xml data into a java application.
    can anybody guide me how to do it.
    the following is my file.
    //MyLogin.java
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    class MyLogin extends JFrame implements ActionListener
         JFrame loginframe;
         JLabel labelname;
         JLabel labelpassword;
         JTextField textname;
         JPasswordField textpassword;
         JButton okbutton;
         String name = "";
         FileOutputStream out;
         PrintStream p;
         Date date;
         GregorianCalendar gcal;
         GridBagLayout gl;
         GridBagConstraints gbc;
         public MyLogin()
              loginframe = new JFrame("Login");
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              labelname = new JLabel("User");
              labelpassword = new JLabel("Password");
              textname = new JTextField("",9);
              textpassword = new JPasswordField(5);
              okbutton = new JButton("OK");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labelname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 5;
              gl.setConstraints(textname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 10;
              gl.setConstraints(labelpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 10;
              gl.setConstraints(textpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 15;
              gl.setConstraints(okbutton,gbc);
              Container contentpane = getContentPane();
              loginframe.setContentPane(contentpane);
              contentpane.setLayout(gl);
              contentpane.add(labelname);
              contentpane.add(labelpassword);
              contentpane.add(textname);
              contentpane.add(textpassword);
              contentpane.add(okbutton);
              okbutton.addActionListener(this);
              loginframe.setSize(300,300);
              loginframe.setVisible(true);
         public static void main(String a[])
              new MyLogin();
         public void reset()
              textname.setText("");
              textpassword.setText("");
         public void run()
              try
                   String text = textname.getText();
                   String blank="";
                   if(text.equals(blank))
                      System.out.println("First Enter a UserName");
                   else
                        if(text != blank)
                             date = new Date();
                             gcal = new GregorianCalendar();
                             gcal.setTime(date);
                             out = new FileOutputStream("log.txt",true);
                             p = new PrintStream( out );
                             name = textname.getText();
                             String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
                             p.println(entry);
                             System.out.println("Record Saved");
                             reset();
                             p.close();
              catch (IOException e)
                   System.err.println("Error writing to file");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equals("OK"))
                   run();
                   //loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    hi, thanks for ur reply.
    i visited that url, i was able to know much about xml.
    so now my requirement is DOM.
    but i dont know how to code in my existing file.
    means i want to know what to link all my textfield to xml file.
    can u please help me out. i am confused.
    waiting for ur reply

  • How to create XML document in Java from scratch ?

    I've downloaded the package generated for my schema.
    Now I'm trying to create a XML Document using the interfaces generated and the
    xmlbeans package. In documentation, all samples start with a call to XmlLoader.load(xmlinput).
    In my case I've no xmlinput, I've only java parameters and i need to produce an
    XML document.
    Could you provide a sample code please ?
    Thanks in advance.

    It looks like you only need to use the xmlText() method from the root of any node
    you want to print out to a file. I used a PrintStream() class and then used the
    ps.print(vpDetails.xmlText()); to save to a file.
    Hope this helps.
    Jerald
    "Eric Vasilik" <[email protected]> wrote:
    >
    To create a new, untyped document:
    XmlObject x = XmlLoader.newInstance();
    To create a new, typed document:
    Map options = new HashMap(
    XmlOptions.DOCUMENT_TYPE,
    CustomerDocument.type );
    CustomerDocument cd = (CustomerDocument) =
    XmlLoader.newInstance( options );
    I have changes pending which will alow you to do this more easily:
    CustomerDocument cd = CustomerDocument.Factory.newInstance();
    - Eric
    "Pascal Fuget" <[email protected]> wrote:
    I've downloaded the package generated for my schema.
    Now I'm trying to create a XML Document using the interfaces generated
    and the
    xmlbeans package. In documentation, all samples start with a call to
    XmlLoader.load(xmlinput).
    In my case I've no xmlinput, I've only java parameters and i need to
    produce an
    XML document.
    Could you provide a sample code please ?
    Thanks in advance.

  • How to Generate XML File from Java Code.

    I want to generate the xml file from the java code.
    Could you plz suggest any webSite address with example?

    Here is the code
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    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.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    public class CreateXML {
         private DocumentBuilderFactory factory = null;
         private DocumentBuilder builder = null;
         private Document document = null;
         public CreateXML() {
              try {
                   factory = DocumentBuilderFactory.newInstance();
                   builder = factory.newDocumentBuilder();
                   document = builder.newDocument();
              } catch (FactoryConfigurationError e) {
                   e.printStackTrace();
              } catch (ParserConfigurationException e) {
                   e.printStackTrace();
         /** Creates the document for xml. */
         public Document createDocument(){
              try{               
                   Element root = document.createElement("Root");
                   Element child = document.createElement("child");
                   root.appendChild(child);
                   document.appendChild(root);
              }catch(RuntimeException e){
                   e.printStackTrace();
              return document;
         /** Saves the document as xml. */
         public void saveDocument(Document document){
              try{
                   TransformerFactory transFactory = TransformerFactory.newInstance();
                   Transformer transformer = transFactory.newTransformer();
                   DOMSource source = new DOMSource(document);
                   StreamResult stream = new StreamResult(new File("sample.xml"));
                   transformer.transform(source, stream);
                   System.out.println("XML Created !!");
              }catch(TransformerConfigurationException e){
                   e.printStackTrace();
              } catch (TransformerException e) {
                   e.printStackTrace();
         public static void main(String args[]){
              CreateXML createXML = new CreateXML();
              Document document = createXML.createDocument();
              createXML.saveDocument(document);
    }

Maybe you are looking for