Manipulating an existing XML document

Hi,
is it possible to use SAX to parse an XML document and append new elements to it?
i know it can be done using DOM but in this case DOM is too expensive so is there any way that the same can be achieved using SAX?
Any help is greatly appreciated

Hi,
You can parse an XML Document using SAX. You can use JClark's Package which is used to parse an XML Document using SAX. Package can be downloaded from www.jclark.com
Try this....

Similar Messages

  • Existing XML documents into KM

    Hello Everyone
    Is there a way to load existing xml documents into KM and then maintain them using xml forms built using the form builder. Any help is greatly appreciated.
    Thanks
    Swetha

    Hi Renuka
    You can move the XML projects from one server  to another.The Xml forms created is stored in the path 'etc\xmlforms' in KM. You can send it out and Upload to the target server instead of creating the same in the Target server from the scratch.
    Regards
    Geogi

  • How to add a new node into existing XML Document

    I have a very simple question. I use XML as input argument for PL/SQL procedure that inserts data into the corresponding table. All I have to do is to add a new tag for Primary Key column and put sequence.NEXTVAL - value into it.
    <ROWSET>
    <ROW>
    -- Add <ID_table_name> value </ID_table_name> ??????
    <FIELD1>data1</FIELD1>
    <FIELD2>data1</FIELD2>
    </ROW>
    </ROWSET>
    I've parsed XML, but I couldn't find the way how to insert the new NODE.
    If you know how to use packages XMLDOM, XMLParser for this purpose, please help me!
    Oracle version 8.1.7

    DOMParser parser=new DOMParser();
    XMLDocument xmlDocument=parser.getdocument();
    Node node=xmlDocument.selectSingleNode("/ROWSET/ROW");
    Element element=xmlDocument.createElement(String tagName)
    node.appendChild(element);

  • Inserting an element into an XML document

    I am simply looking insert a new element into an existing XML Document using JDOM. Here is my code so far:
    public class UserDocumentWriter {
         private SAXBuilder builder;
         private Document document;
         private File file = new File("/path/to/file/users.xml");
         private Element rootElement;
         public UserDocumentWriter() {
              builder = new SAXBuilder();
              try {
                   document = builder.build(file);
                   rootElement = document.getRootElement();
              } catch (IOException ioe) {
                   System.err.println("ERROR: Could not build the XML file.");
              } catch (JDOMException jde) {
                   System.err.println("ERROR: " + file.toString() + " is not well-formed.");
         public void addContact(String address, String contact) {
              List contactList = null;
              Element contactListElement;
              Element newContactElement = new Element("contact");
              newContactElement.setText(contact);
              List rootsChildren = rootElement.getChildren();
              Iterator iterator = rootsChildren.iterator();
              while (iterator.hasNext()) {
                   Element e = (Element) iterator.next();
                   if (e.getAttributeValue("address").equals(address)) {
                        contactListElement = e.getChild("contactlist");
                        contactListElement.addContent(newContactElement);
                        writeDocument(document);
         public void writeDocument(Document doc) {
              try {
                   XMLOutputter output = new XMLOutputter();
                   OutputStream out = new FileOutputStream(file);
                   output.output(doc, out);
              } catch (FileNotFoundException ntfe) {
                   System.err.println("ERROR: Output file not found.");
              } catch (IOException ioe) {
                   System.err.println("Could not output document changes.");
         }However, the problem is, the newly added element will always be appended to the end of the last line, resulting in the following:
    <contactlist>
                <contact>[email protected]</contact><contact>[email protected]</contact></contactlist>Is there anyway in which I can have the newly added element create it's own line for the purpose of tidy XML? Alternatively is there a better methodology to do the above entirely?

    Your question is not very clear.
    Do you want to know How to insert an element into an XML document?
    Answer: I can see you already know how to do it. You have added the element using addContent()
    or do you want to know How to display the XML in a tidy format?
    Answer: to view the XML in a properly formatted style you can you the Format class. A very basic way of viewing the XML would be:
       * Prints the Document to the specified file.
       * @param doc
       * @param filename
       * @param formatting
      public static void printDocToFile(Document doc, String strFileName,
          boolean formatting)
        XMLOutputter xmlOut = null;
        if (!formatting)
          xmlOut = new XMLOutputter();
        } else
          Format prettyFormat = Format.getPrettyFormat();
          prettyFormat.setOmitEncoding(false);
          prettyFormat.setOmitDeclaration(false);
          xmlOut = new XMLOutputter(prettyFormat);
        try
          if (doc != null)
            FileWriter writer = new java.io.FileWriter(strFileName, true);
            xmlOut.output(doc, writer);
            writer.flush();
            writer.close();
          } else
            System.out.println("Document is null.");
        catch (Exception ex)
          System.out.println(ex);
      }

  • Creating a node in an XML Document

    Hi!
    i need to insert a new element in an existing xml document. for example,
    <bookinfo>
    <book>
    <bookname>A</bookname>
    <author>B</author>
    </book>
    <book>
    <bookname>C</bookname>
    <author>D</author>
    </book>
    </bookinfo>
    In this document if i want to insert another element using Xpath, say,<publisher> in <book> node, how to insert it.
    I'm using DOM parser for parsing the xml file.
    Any help to solve this issue appreciated.
    Thanks in advance.

    final class Foo {
        private static final String MARKUP =
            "<bookinfo>\n" +
              "<book isbn='1234'>\n" +
              "<bookname>A</bookname>\n" +
              "<author>B</author>\n" +
              "</book>\n" +
              "<book isbn='5678'>\n" +
              "<bookname>C</bookname>\n" +
              "<author>D</author>\n" +
              "</book>\n" +
              "</bookinfo>";
        private Foo() {
            super();
        public static final void main(final String[] args)
            throws XPathExpressionException {
            String isbn = args.length > 0 ? args[0] : "1234";
            String publisher = args.length > 1 ? args[1] : "Sample Publisher";
            Document document = ...  // Initialize somehow
            XPath xpath = XPathFactory.newInstance().newXPath();
            String expression = "//bookinfo/book[@isbn=" + isbn + "]";
            Element book = (Element) xpath.evaluate(expression, document.getDocumentElement(), XPathConstants.NODE);
            if (book == null) {
                throw new RuntimeException("Unable to find ISBN " + isbn);
            Element newPublisher = document.createElement("publisher");
            newPublisher.setAttribute("name", publisher);
            book.appendChild(newPublisher);
    }- Saish

  • Problem in editing xml document

    Hi,
    Can anybody help me out of this problem basically i want to develop sample prog that will take care of editng the existing xml document eg. i want to edit resource file for the application like if user want to change some property through the user interface and i want to reflect that input to the xml files.
    Help me as soon as possible ............. its very urgent .......................
    Regards
    Sanket

    Output document with a transformer.
    TransformerFactory tFactory =TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer();
                DOMSource source = new DOMSource(document);
                StreamResult result = new StreamResult(new File("c:/output/output.xml"));
                transformer.transform(source, result);

  • How to split XML document into two

    I want to create new docuemnt by taking part of the existent XML document under the node document_text
    vNodeList := xmldom.getElementsByTagName(vdoc, 'document_text');
    vNode := xmldom.item(vNodeList, 0); -- The xmldom.getNodeName(vNode) of this node is exactly what i am
    -- looking for
    vdoc:= xmldom.makeDocument( vNode);
    insert into cltab values (empty_clob()) returning cl into cl;
    xmldom.writeToClob(vdoc_txt, cl);
    But after that i am still getting the whole document tree, - copy of the whole document.
    What am i doing wrong? What functions should i use for this kind of task? xmldom.clonenode?
    Could you recommend any good description of the xmldom package?
    Thanks,
    Roman

    If you are using an FI  entry F-43 to generate invoice this can be done by giving the same invoice ref. in the Inv. Ref. field  for two vendors. This is manual
    Document Split will split the document between two profit center and not between vendors.

  • XML document creation

    Does anyone know of a Javascript or PHP script that will
    allow a client to create new and update existing xml documents that
    can be used with the Spry Dataset, through an admin area?

    I don't know of such a system. We do have a script that can
    convert queries to XML:
    http://labs.adobe.com/technologies/spry/samples/utils/query2xml.html
    And I know there are PHP scripts for inserting and updating
    records in a database, which might be easier.
    Hope this helps,
    Donald Booth
    Adobe Spry Team

  • Create xml document by xpath in java

    as i know, i can navigate existing xml document by xpath in java, i wonder if i can create a xml document framework by xpath in java?
    something like:
    Document doc = someobject.create(xpath expression);
    then i can use DOM to fill the framework?
    Thanks

    Please refer
    http://www.packtpub.com/article/xpath-support-in-oracle-jdeveloper-xdk-11g

  • Using JAXB to edit XML documents

    I am trying to understand how (and whether) JAXB can be used to make the following types of changes to an existing XML document. I know that I can EDIT an XML document using the set methods that are generated by JAXB (in conformance with the XML Schema), and then I create a Marshaller and marshall the root element object.
    However, I have not figured out how to do any of the following:
    (i) insert a new element
    (ii) delete an existing element
    (iii) reorder elements.
    Here is an excerpt from an XML document:
    <directory name="dir">
    <file name="file1"/>
    <file name="file2"/>
    <file name="file3"/>
    </directory>
    The order in which the file elements appear is significant.
    If I want to add a new file (file4), how would I do this? Where would it be added, at the end? What if I wanted to add it after file2?
    If I want to delete file1, I don't know how to do that.
    Finally, if I want to move file2 after file3, I don't know how to do that.
    It seems as though I need access to the underlying com.sun.xml.bind.util.ListImpl (or similar collection object), which holds the actual file elements when JAXB unmarshals the xml file. However, this seems dangerous and I have gotten a concurrent access exception while trying to do something like this. (Another problem has to do with iterators, where I can't iterate through a list and then make a change to the list w/o messing up the iterator.)
    If there are any technologies other than JAXB that might accomplish this, but that provide data binding, I would be happy to hear about it. (I could try SAX/DOM/JDOM/DOM4J or XSLT, I guess, but I like the data binding of JAXB.)

    As is typical for me, I answered my own questions.
    if you are outside of an iterator, you can simply use the:
    add(object)
    add(position,object)
    remove(object)
    methods of the List interface to add and remove elements from the list of elements.
    Also, if you use a ListIterator, you can call the add() and remove() methods of ListIterator while iterating through the list.
    In order to reorder elements in the list, use:
    Collections.swap(list,pos1,pos2). Why this method is not built into the List interface itself is beyond me. This was only added in 1.4, btw.

  • How do I add XML content to existing FrameMaker Document

    Hello,
    I have an XML document that contains features of one item and I want to add data from it to FM document that shows those features. These features have been added to FM previously by copy-paste technology which isn't obviosly the fastest way and I have understood adding them automatically is possible.
    I can read XML well and I can produce XSLT files to make another XML files, problem is that I'm a little beginner with FM and help files didn't show any good examples of this (or at least I didn't find). I tried to do some read/write rules, because it seemed to be the way how FM handles these things but they didn't work.
    So shortly: XML file (data) + FM file (tables and such) = FM file which have XML data in its tables
    I would appreciate any help, like pointing to right help files or such, thanks in advance.

    The two main references you need are:
    Developing Structured Applications with FrameMaker, Guide
    Developing Structured Applications with FrameMaker, Reference
    They used to ship with FrameMaker, but you can download them from the Adobe site. Check the Support section. I do not believe they are available for FrameMaker 10 yet, but they are for version 9. No matter your FramMaker version, almost any set will do.
    Basically, you need an XSLT that will translate the XML structure into the structure you use in your FrameMaker files. You need a set of read/write rules (see the references above). FrameMaker uses read/write rules to specify how certain FrameMaker objects are to be translated from the XML. Such objects include tables, variables, and markers.
    Then you need to create a structured application that specifies where the XSLT, the read/write rules, and your structured template are located on you system.Again, see the references.
    Once all of the above is in place, you open the XML file from within FrameMaker. FrameMaker will ask you what structured application to use, which you pick from the dropdown list. It will then open the XML file, apply the XSLT transformation, and copy the result into your structured blank template. That process will likely list several errors, which you may or may not be able to ignore depending upon the resulting FrameMaker document. In my case, these are usually errors about missing graphics, which I already know are missing.
    The result is ONE FrameMaker file. You can then copy and paste the information where ever you need it in your other documents. I am not sure whether you can import an XML file into an existing Framemaker document, much like a text inset. Maybe others will know.
    Good luck,
    Van

  • Manipulating an XML document!

    Hi every1,
    I am working on my dissertation which is based on XML. I need 2 b able 2 change the text of a node in an XML document.
    E.g., <price> </price>.
    I need 2 insert a value betweem these tags.
    I have downloaded JAXP, but it seems 2 b mising a package named xmlDocument.
    Can any1 help?
    Thanx!

    I am using Xerces for creating XML documents.
    If you have created an element, you can use the method createTextNode on your document object in order to create the text. Once you have done this, you can call the appendChild method on the element to add the text. E.g.
    Element element = xmlDoc.createElement("price");
    Text elementText = xmlDoc.createTextNode("1.99");
    element.appendChild(elementText);
    This would produce the following:
    <price>1.99</price>
    This is the Xerces implementation but there should be similar functionality within most of the XML api's.
    Hope this helps.

  • Any available tools for formating xml document?

    Hi, I'm just looking for a java tool can help me sorting the xml document and text in alphabetical order. Anybody has any suggestion? Thanks a lot.

    Well, you don't have to write your own sort necessarily. You'll have to write a Comparator to use with an existing sort routine, and you'll probably have to do some non-trivial manipulation of data just to get it to a point where you can use the existing sort routine.
    Of course, depending on the situation, writing your own sort might be easier. (Say, if you were merging two sorted documents into one.)

  • Error while loading an XML document using a structured application

    Hi,
    I try to load an XML document using a structured application defined in the default structapps.fm
    My code is shown down, extracted from the FDK API code sample.
    Problem, I always have the same message :
    "Cannot find the file named e:\xml\AdobeFrameMaker10\file. Make sure that the file exists. "
    Where "e:\xml\AdobeFrameMaker10\" is my install directory.
    So I assume that frame try to find the structapps.fm file but does not find it.
    What else can it be ?
    Does anyone knowns how to achieve this simple task using extendScript ?
    Thanks for any comments, Pierre
    function openXMLFile(myLastFile) {
        var filename = myLastFile.openDlg("Choose XML file ...", "*.xml", false);
        if (filename != null) {
            /* Get default open properties. Return if it can’t be allocated. */
            var params = GetOpenDefaultParams();
            /* Set properties to open an XML document*/
            /*Specify XML as file type to open*/
            var i = GetPropIndex(params, Constants.FS_OpenAsType)
            params[i].propVal.ival = Constants.FV_TYPE_XML;
            /* Specify the XML application to be used when opening the document.*/
            i = GetPropIndex(params, Constants.FS_StructuredOpenApplication)
            params[i].propVal.sval = "myApp";
            i = GetPropIndex(params, Constants.FS_FileIsOldVersion)
            params[i].propVal.ival = Constants.FV_DoOK
            i = GetPropIndex(params, Constants.FS_FontNotFoundInDoc)
            params[i].propVal.ival = Constants.FV_DoOK
            i = GetPropIndex(params, Constants.FS_FileIsInUse)
            params[i].propVal.ival = Constants.FV_DoCancel
            i = GetPropIndex(params, Constants.FS_AlertUserAboutFailure)
            params[i].propVal.ival = Constants.FV_DoCancel
            /*The structapps.fm file containing the specified application must have
            already been read. The default structapps.fm file is read when FrameMaker is
            opened so this shouldn't be a problem if the application to be used is
            listed in the structapps.fm file.*/
            var retParm = new PropVals()
            var fileObj = Open(filename, params, retParm);
            return fileObj
        } else {
            return null;

    Pierre,
    Depending on the object "myLastFile", the method openDlg might not even exist (if the myLastFile object is not a File object, for instance). And I do not see any need for the myLastFile anyhow, as you are presenting a dialog to select a file to open. I recommend using the global ChooseFile( ) method instead. This will give you a filename as string in full path notation, or null when no file was selected in the dialog. I am not sure what your ExtendScript documentation states about the return value for ChooseFile, but if that differs from what I am telling you here, the documentation is wrong. So, if you replace the first lines of your code with the following it should work:
    function openXMLFile ( ) {
        var filename = ChooseFile ( "Choose XML file ...", "", "*.xml", Constants.FV_ChooseSelect );
    While writing this, I see that Russ has already given you the same advice. Use the symbolic constant value I indicated to use the ChooseFile dialog to select a single file (it can also be used to select a directory or open a file - but you want to control the opening process yourself). Note that this method allows you to set a start directory for the dialog (second parameter). The ESTK autocompletion also gives you a fifth parameter "helplink" which is undocumented and can safely be ignored.
    Good luck
    Jang

  • How do i update an existing XML File?

    Hello, I have the following xml file gps.xml:<?xml version="1.0"?>
    <!DOCTYPE gps SYSTEM "gps.dtd">
    <gps>
       <latitude>43.00000</latitude>
       <longitude>-83.00000</longitude>
    </gps> I already have methods written to get the values. But how can I change these values and update the file to reflect these changes?
    thanks for your help!

    Hi, I already have this following code. I would just like to add a method to it to update the existing XML file with different lat/lon coordinates. Could you please help me out with it? thanks
    import java.io.*;
    import java.io.PrintWriter;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    public class Gps implements java.io.Serializable {
        private double latitude_;
        private double longitude_;
        public Gps(Document doc) {
            setup(doc.getDocumentElement());
        public Gps(String uri) throws IOException, SAXException, ParserConfigurationException {
            setup(uri);
        public void setup(Document doc) {
            setup(doc.getDocumentElement());
        public void makeElement(Node parent) {
            Document doc;
            if (parent instanceof Document) {
                doc = (Document)parent;
            } else {
                doc = parent.getOwnerDocument();
            Element element = doc.createElement("gps");
            int size;
            URelaxer.setElementPropertyByDouble(element, "latitude", this.latitude_);
            URelaxer.setElementPropertyByDouble(element, "longitude", this.longitude_);
            parent.appendChild(element);
         public Document makeDocument() throws ParserConfigurationException {
            Document doc = UJAXP.makeDocument();
            makeElement(doc);
            return (doc);
        public final double getLatitude() {
            return (latitude_);
        public final void setLatitude(double latitude) {
            this.latitude_ = latitude;
        public final double getLongitude() {
            return (longitude_);
        public final void setLongitude(double longitude) {
            this.longitude_ = longitude;
       public final void updateXmlFile(double latitude, double longitude) {
         // something???
        public final void updateXmlFile(double latitude, double longitude) {
            this.latitude_ = latitude;
            this.longitude_ = longitude;
        public String makeTextDocument() {
            StringBuffer buffer = new StringBuffer();
            makeTextElement(buffer);
            return (new String(buffer));
        public void makeTextElement(StringBuffer buffer) {
            int size;
            buffer.append("<gps");
            buffer.append(">");
            buffer.append("<latitude>");
            buffer.append(Double.toString(getLatitude()));
            buffer.append("</latitude>");
            buffer.append("<longitude>");
            buffer.append(Double.toString(getLongitude()));
            buffer.append("</longitude>");
            buffer.append("</gps>");
        public String toString() {
            try {
                return (makeTextDocument());
            } catch (Exception e) {
                return (super.toString());
    }

Maybe you are looking for

  • How do I remove space after paragraph?

    Does Robohelp have the "Remove Space after paragraph" button for reducing the space between lines, like the one in Word?

  • Polish characters in text input (linux problem only)

    I've got some problems with TextInput. When i want to type polish characters (RIGHT ALT + combination: A,C,E,L,N,O,S,Z and X) - I've got no results. This happend only in linux versin - windows is ok. Could be a problem with player... Any idea or quic

  • PO cratead by Purchasing group using different Purchase Requisition

    Hi Friends, Please tell me the transaction and process of the following scenario. More than 100 requestors are creating purchase Requisitions for different materials. How the  purchase group will come to know all this purchase requisitions while crea

  • Reimporting WebService from Service Registry into WD Model (DC type = WD)

    Hello We're facing a strange behaviour when trying to reimport a webservice from our service registry. We renamed some attributes in our application service / business object (within CAF), generated, built and redeployed everything and then did the r

  • Separate iTunes Music & Video Folders

    Bothered by the fact that I can't have a separate folder location for my iTunes Music, Apps, Videos, Books, etc. My Music folder is pushing 400GB and I'd like to keep it on an external drive at my office (where I do most of my listening). On the othe