How to create nested xml tags using java parser?

Hi,
I need to create a xml file containing following tags using java program-
<A attr1="abc">
<B attr2="xyz">
<C attr3="pqr"> </C>
</B>
</A>
Can anyone please let me know which parser should I use to create the above mentioned xml file?
If possible, please post a code snippet for the same.
Thanks in advance..

Well, you could start by doing it all the 'old fashioned' way; create a String object containing that text and then write it away to a file. Or you could take the time to look at the javadoc for all of the xml support that the Java language itself supplies - XMLReader/Writer for a start. After that put together some code that you think would do the job and ask for help on any specific problems you encounter.

Similar Messages

  • 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

  • How to comment the xml tags using java

    Iam using a xml file i want to comment some of the tags in that file

    And your quesion is? Did you parse it into a Document and do you want to write a changed version into another file?

  • 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 write as XML file using java 1.5

    hi all,
    i am trying to create an XML file using java 1.5. I took a XML creating java file which was working with java 1.4 and ported same file into java 1.5 with changes according to the SAX and DOM implmentation in java 1.5 and tried to compile. But while writing as a file it throws error "cannot find the symbol."
    can any body help me out to solve this issue.......
    thankx in advance
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.NamedNodeMap;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.DocumentHandler;
    import org.xml.sax.InputSource;
    import org.xml.sax.helpers.ParserFactory;
    import java.io.*;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();                   
                   dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();                   
    Document xmlDoc =  db.newDocument();
    // this creates the xml document ref
    // parent node reference
    Element rootnd = (Element) xmlDoc.createElement("ALL_TABLES");
    // root node
    xmlDoc.appendChild(rootnd);
    Element rownd = (Element) xmlDoc.createElement("ROW");
    rootnd.appendChild(rownd);
    Element statusnd = (Element) xmlDoc.createElement("FILE_STATUS");
    rownd.appendChild(statusnd);
    statusnd.appendChild(xmlDoc.createTextNode("Y")
    FileOutputStream outpt = new FileOutputStream(outdir + "//forbranch.xml");
    Writer outf = new OutputStreamWriter(outpt, "UTF-8");
    //error is occuring here Since write method is not available in the Document class
    xmlDoc.write(outf);
    outf.flush();

    Hi,
    when I look in the JDK1.4.2 specification I don't see any write method in the Document interface.
    However, your solution is the Transformer class. There you transform your DOM tree into any output you need. Your code sould look something like this:     TransformerFactory tf = TransformerFactory.newInstance();
         // set all necessary features for your transformer -> see OutputKeys
         Transformer t = tf.newTransformer();
         t.transform(new DOMSource(xmlDoc), new StreamResult(file));Then you have your XML file stored in the file system.
    Hope it helps.

  • How to create a packet by using java?

    Hi, i am currently working on a research and i have some problems here.
    1) how to create a packet by using java programming ?
    2) How can i set the packet's information (e.g: packet's length, size of its header, etc) by using java?
    I am currently in a midst of this now and i hope that someone is willing to correspond to my questions and help me out of it.
    Thank you!

    I wan to create a customize packet where the user can
    define the header size, the packet's length etc. in
    the program......Then you get to write it to the connection yourself. Look at the OutputStream classes to see how to write low level output to a connection.

  • Creating an XML file using Java Standalone

    Hi,
    My problem is -
    1) write a java stand alone retrieving data from database and put the data in XML format (i.e; we have to create an XML file).
    How to do this? Could any one of you please suggest me how to code or can i have any links that refer the code snippets.
    Thanks.

    Could someone give me a link with information on how SAX is used to create an XML?
    null

  • How to Update existing XML File Using Java Swing

    Hi,
    I am reading XML file and getting keywords into JList. When i add some keywords into JList through textfield and remove keywords JList, then after click on save button it should update xml file. How can i do it ?
    Please provide me some code tips for updating xml file
    This is the code that i am using for reading XML File:
    import javax.swing.*;
    import java.awt.event.*;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    import java.io.IOException;
    import java.util.*;
    import java.text.Collator;
    import java.util.regex.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import com.cloudgarden.layout.AnchorConstraint;
    import com.cloudgarden.layout.AnchorLayout;
    public class getKeywords extends JFrame implements ActionListener
    static JPanel p;
    static JLabel lbl;
    static JButton btnSave,btnAdd,btnRemove;
    static String path;
    static Vector v;
    static JList lstCur;
    static JTextField txtKey;
    Document dom;
    static image imgval;
    NodeList nodelstImage;
    static AnchorLayout anchorLay;
    private DefaultListModel lstCurModel;
    public getKeywords()
         super("Current Keywords");
        v=new Vector();
        p=new JPanel();
        txtKey=new JTextField(10);
        btnAdd=new JButton("Add");
        btnRemove=new JButton("Remove");
        btnSave=new JButton("Save");
        lbl=new JLabel("Current Keywords");
        lstCurModel=new DefaultListModel();
            lstCur=new JList();
            JScrollPane scr=new JScrollPane(lstCur);
        runExample();
         lstCur.setModel(lstCurModel);
         p.add(lbl);
         p.add(scr);
         p.add(txtKey);
         p.add(btnAdd);
         p.add(btnRemove);
         p.add(btnSave);
         add(p);
         btnAdd.addActionListener(this);
         btnRemove.addActionListener(this);
         btnSave.addActionListener(this);
         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    public static void main(String arg[])
         getKeywords g=new getKeywords();
         g.resize(250,400);
         g.setVisible(true);     
    public void actionPerformed(ActionEvent ae)
         if(ae.getSource()==btnAdd)
              lstCurModel.addElement(txtKey.getText());
         if(ae.getSource()==btnRemove)
              lstCurModel.remove(lstCur.getSelectedIndex());
         if(ae.getSource()==btnSave)
              //Code to Write
         public void runExample()
              //Parse the XML file and get the DOM object
              ParseXMLFile();
              //Get the Detail of the Image Document
              parseImageDocument();
              //Get the Detail of the LML Document
              //parseLMLDocument();
              //System.out.println(lmlval.Title);
         public void ParseXMLFile()
              //Get the Factory
              DocumentBuilderFactory builderFac = DocumentBuilderFactory.newInstance();
              try
                   //Using factory get an instance of the Document Builder
                   DocumentBuilder builder = builderFac.newDocumentBuilder();
                   //parse using builder to get DOM representation of the XML file
                   dom = builder.parse("LML.xml");
              catch(ParserConfigurationException pce)
                   pce.printStackTrace();
              catch(SAXException sax)
                   sax.printStackTrace();
              catch(IOException ioex)
                   ioex.printStackTrace();
         public void parseImageDocument()
              //Get the root element
              Element docImgEle = dom.getDocumentElement();
              //Get a nodelist for <Image> Element
              nodelstImage =  docImgEle.getElementsByTagName("Image");
              if(nodelstImage != null && nodelstImage.getLength() > 0)
                   for(int i = 0; i < nodelstImage.getLength(); i++)
                        //Get the LML elements
                        Element el = (Element)nodelstImage.item(i);
                        //Get the LML object
                        getImage myImgval = new getImage();
                        imgval = myImgval.getimage(el);
                        v.addElement(new String(imgval.Thumb));
                        String[] x = Pattern.compile(",").split(imgval.Keys);
                        for (int s=0; s<x.length; s++)
                        lstCurModel.addElement(x[s].trim());
                        //System.out.println(x[s].trim());
    }     Thanks
    Nitin

    You should update your DOM document to represent the changes that you want made.
    Then, using the Transformation API you simply transform your document onto a stream representing your file. Something like this:
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    // TODO - set indentation amount!
    Source source = new DOMSource(dom);
    Result result = new StreamResult(file);
    transformer.transform(source, result);Hope this helps.

  • How to create outllok Distribution list using java

    Hi all,
    I have a requirement to create a outlook Distrubution list by reading all the email ids from the SQL database.
    and it has to be dynamic ie when ever a new User is registered it has to be updated.
    is there any APis are exist to do so.if yes please reply to this post .
    I searched the google but no help till now.so thought of posting a query here.
    Thanks for all in advance.
    hope to get reply from anyone of u ...

    hi steve
    first of all sorry for the delay in replying
    JOC is a commertial product and im completely looking for open source apis if any
    i need to create the outllok DL (list of emails from datadabse) from the java code and sent a mail to that DL using java mail apis.
    if u have any suggetions or thoughts are welcome.

  • How to create pdf files dynamically using Java

    I am new to java world. I got a task of generating dynamic pdf files using Java. I have tried with some third party APIs for generating pdf. But most of them are not so feasable. I am looking for source code for one such APIs so that I can build my custom requirements over it.
    Thanks

    I am new to java world. I got a task of generating
    dynamic pdf files using Java. I have tried with some
    third party APIs for generating pdf. But most of
    them are not so feasable. Which ones? What was wrong with them?
    I am looking for source
    code for one such APIs so that I can build my custom
    requirements over it.What are your exact requirement?

  • Q: How to access and modify xml tags using Java

    I have an xml based document that i need to access and change. For example, the code
    <section id="section1">
    <div>
    <xforms:group id="id1">
    <xforms:label id="label1">
    <l style="font-size:16pt"> something </l>
    </xforms:label>
    </xforms:group>
    </div>
    </section>
    Working with Java I need to access all the tags, select some of them that are relevant to the current device and remade the document. I thought I would read the file character by character identifying the different labels and building a tree, storing in the tree nodes the relevant information as some kind of attributes (for example, in the case of the <xforms:group id="id1"> I would name the node "xforms:group" and create an "id" attribute with value "id1"). I'm not sure if that is the most efficient way of accessing the problem (computational power might be an issue), and would appreciate some help on the subject.
    Thanks,

    this may help you..
    this is a little util i made to help me read/write files.
    using this, you are only one step away from your solutions, you only need to figure out the regex you need to run on the text of the file to make it become what you need it to become.
    though if you use non-standard encoding, you might not want to use this code..
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    public class ASCIIFile {
         private File file;
         private StringBuilder builder;
         public ASCIIFile(String path) throws IOException{
              file = new File(path);
              openFile();
         public ASCIIFile(File file) throws IOException{
              this.file = file;
              openFile();
         public void setNewFileName(String fileName){
              file = new File(file.getAbsolutePath(), fileName);
         public void setNewFilePath(String filePath){
              file = new File(filePath, file.getName());
         private void openFile() throws IOException{
              if(!file.exists()) file.createNewFile();
              BufferedReader read = new BufferedReader(new FileReader(file));
              String line = read.readLine();
              builder = new StringBuilder();
              while(line != null){
                   builder.append(line);
                   builder.append("\n");
                   line = read.readLine();
              read.close();
         public String getContents(){
              return builder.toString();
         public StringBuilder getStringBuilder(){
              return builder;
         public void setStringBuilder(StringBuilder b) throws IOException{
              setContents(b.toString());
         public void setContents(String contents) throws IOException{
              FileWriter writer = new FileWriter(file);
              writer.write(contents);
              writer.flush();
              writer.close();
              builder = new StringBuilder(contents);
         public static File[] getAllFilesUnderDir(String fullpath, boolean recursive) {
              ArrayList queue = new ArrayList(10);
              ArrayList matched = new ArrayList();
              File root = new File(fullpath);
              File[] files = root.listFiles();
              if (files == null || files.length == 0) {
                   return new File[] {};
              queue.addAll(Arrays.asList(files));
              for (int j = 0; j < queue.size(); j++) {
                   File child = (File) queue.get(j);
                   if (child.isDirectory() && recursive) {
                        files = child.listFiles();
                        if (files != null) {
                             queue.addAll(Arrays.asList(files));
                   } else { // child is file
                        matched.add(child);
              return (matched.size() > 0)?((File[]) matched.toArray(new File[] {})):(new File[] {});
    }

  • Problems in creating xml tags using java

    i had analysed the xmlnode builder class but i am unable to learn what is the functions of that class.
    so please send me a sample coding to create the following output.
    i need this kind of output.
    <?xml version="1.0"?>
    <tree>
    <node id="acc" text="Accounts" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="1" text="Liabilites" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="5" text="Capital" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="L5" text="Gods A/c" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    </contents>
    </node>
    <node id="10" text="Current Liablities" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    <node id="11" text="Cash On Hand" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="L11" text="Cash" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    </contents>
    </node>
    <node id="12" text="Bank Balance" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="L12" text="ICICI" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    </contents>
    </node>
    </contents>
    </node>
    <node id="2" text="Asset" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="6" text="Fixed Asset" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2"/>
    </contents>
    </node>
    <node id="3" text="Expenses" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="15" text="Direct Expenses" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2">
    <contents>
    <node id="8" text="Purchase" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2"/>
    </contents>
    </node>
    <node id="16" text="InDirect Expenses" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2">
    <contaents>
    <node id="L16" text="Staff Welfare" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2"/>
    </contaents>
    </node>
    </contents>
    </node>
    <node id="4" text="Income" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="13" text="Direct Income" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2">
    <contents>
    <node id="7" text="Sales" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2"/>
    </contents>
    </node>
    <node id="14" text="InDirect Income" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con2"/>
    </contents>
    </node>
    </contents>
    </node>
    <node id="inv" text="Inventory" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="1" text="Raw Material" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1">
    <contents>
    <node id="I1" text="Pigments" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    </contents>
    </node>
    <node id="2" text="Intermediate" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    <node id="3" text="Work In Process" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    <node id="4" text="Finised Goods" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    <node id="5" text="Packing Materials" cImage="tree/images/book.gif" oImage="tree/images/bookopen.gif" contextid="con1"/>
    </contents>
    </node>
    </tree>

    Unless you are using some special tag library or something, SQL is not, as far as I've ever seen, going to handle while loops within the statements. You want to create the table, then you have to create the CREATE statement string
    String c = "CREATE TABLE [dbo].[tblNewTable] (";
    for(int x = 0; x < vFieldFruitVector.size(); x++) {
       c += vFieldFruitVector.get(x) + " char 50 COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL";
    c += ")";
    int res = stmt.executeUpdate(c);

  • Search and Replace XML TAG using JAVA

    Hi All,
    I have an XML file, say RESULT.XML Which has about 30000 Lines (yes Thirty Thousand ). For some reason i need to replace an existing tag with a different tag(not the value inside the tag, But the tag itself) . I am facing a challenge. I will explain it as below.
    I have a csv file which has 2 values as given below
    <VALUE A> , <VALUE B>
    where <VALUE A> is an existing node in the RESULT.XML and <VALUE B> is the node that should replace <VALUE A> in the RESULT.XML
    i have 500 such entries in the file.
    Now i need to write a program to read the csv file, Search <VALUE A> in the RESULT.XML and Replace it with <VALUE B> of the csv file.
    please let me know how do i start with this.
    I really want to fix this issue.
    Existing Node = <Product ID="role (contact) 3" UserTypeID="Product Number">_
    To be changed to = <Product ID= role (contact)3" UserTypeID="Product Number">_
    please reply if you need any further information
    Thanks in Advance
    Manzoor

    Sounds like a job for XSLT or Perl not Java though it can be done in Java. In Java I would initially try
    1) Read the csv file using one of the many free CSV parsers and build a Map<String,String>.
    2) Create a Rewriter using the map keys as targets and use the map values as replacements.
    3) Read the XML file line by line and process each line with the Rewriter.
    4) Save each line to an output file.
    For a one-off task this would probably serve but it could prove very slow if you need to run this on a daily basis.

  • How to handle multiple xmls(schemas) using java

    Can anyone give me solution for the below issue.
    We are handling five types of xmls(five different xsds) in our application.We have the XML and its XSD in database. Currently we are using JAXB to create and update the xmls.
    In future there is a chance to add new schema. In that case our current code will not work (because the JAXB is tightly coupled with the xsds) for new schema. Is there any technology or method to handle this situvation?
    I am looking for early respons.
    Thanks
    Dhans

    You have no idea? Then look in your JavaMail download and you will find several sample programs that you can use to get started. It would also help to read the JavaMail FAQ (Google will find it easily for you).

  • Problem creating nested xml data using XSQLServlet

    Hi,
    This is sort of a sql question.
    I'm trying to create a nexted xml data file.
    The data in a rows format can be had using the
    following query...
    SELECT username, portlet_name, count(instance_name) as
    INSTANCE_COUNT
    FROM portlet_user_subscriptions
    GROUP BY username, portlet_name
    to get is back in a hierrachical format, I tried the
    following...
    SELECT distinct(username) as USERNAME,
    CURSOR (
         SELECT portlet_name, count(instance_name) as
    NUM_INSTANCES
         FROM portlet_user_subscriptions T2
         WHERE T2.username=USERNAME
         GROUP BY portlet_name ) AS PORTLETS
    FROM portlet_user_subscriptions T1
    But, that is running the CURSOE for every username in the
    other loop when it should be doing it only for distinct
    usernames.
    What am I doing wrong here...
    cheers,
    Vijay

    How you store the data in the database?
    Basically, you can query the database with XSQL(<xsql:query/>)
    to get the output in XML. Then you can use XSLT to transform it
    to the format you want.
    <?xml-stylesheet type="text/xsl" href="doyouxml.xsl" ?>
    ...

Maybe you are looking for

  • External monitor flickers when scroll on the google stock chart in Safari

    Well, this sounds crazy but this is what is happening to my Retina, 15-inch, Late 2013 Macbook Pro. I can reproduce it. 1. Go to this page in Safari (Version 7.1 (9537.85.10.17.1)): https://www.google.com/finance?q=LQD&ei=nQQ_VPj1H4ebrAHP6oDYDQ 2. Sc

  • Curiosity about the level of load on SAP ERP systems

    Hello all, In my company, I'm in charge of the SAP capacity planning and so, every month, I fill several Excel sheets to follow the load of our systems. I am curious to know if our load is similar to that of other SAP ERP customers. I would be happy

  • Open Dataset non-unicode & default

    Currently im using the open dataset with default then it hit a codepage error. I found out that the file contained characters that is not UTF-8 so when i changed the open dataset to non-unicode the codepage error goes away. Im wondering if there is a

  • Item xref api or interface?

    hi, does anybody know whether there is an api or interface for item cross reference conversion (supplier cross reference, not customer) in R12? thanks..

  • How to enable the "top activities" from the performance in OEM12C?

    We installed the 12C OEM. But the "top activities" and other options are not enabled from performance pane. I tried to set the parameter control_management_pack_access = "DIAGNOSTIC+TUNING" . Does not work. As was told that should be due to the datab