Writing a clean, formatted xml file

Am reworking an xml file with two types entities both with the name "item", one is a base item and the second is an item referred to by the base items.
My task is to replace the child "<mention_ref item_id=xxx/>" with the actual item that xxx refers to, rename that element to "mention_ref" and delete the element I moved. All this part works well.
Hoowever, when I write it out it's not formatted and there a empty lines where the missing elements are.
How can I fix this?
Jim

Tried all that and no change in the output, see below:
     <item id="_491" name="$5,000" norm="$_5_,_000" ontology="entity:numeric:money" type="equiv">
          <mention_ref equiv_id="_491" head="2115" id="_317" name="$5,000" norm="$_5_,_000" ontology="entity:numeric:money" tail="2121" type="mention">
          <attribute name="mention_type" value="name"/>
          <attribute name="currency" value="usd"/>
          <attribute name="norm" value="5000"/>
     </mention_ref>
          <attribute name="mention_type" value="name"/>
          <attribute head="2115" name="name" tail="2121" value="$5,000"/>
          <attribute name="currency" value="usd"/>
          <attribute name="norm" value="5000"/>
     </item>
     <item id="_473" name="Associated Press" norm="associated_press" ontology="entity:organization:company" type="equiv">
          <mention_ref equiv_id="_473" head="2330" id="_333" name="Associated Press" norm="associated_press" ontology="entity:organization:company" tail="2346" type="mention">
          <attribute name="confidence" value="4"/>
          <attribute name="mention_type" value="name"/>
     </mention_ref>
          <mention_ref equiv_id="_473" head="1557" id="_337" name="AP" norm="ap" ontology="entity:organization:company" tail="1559" type="mention">
          <attribute name="confidence" value="2"/>
          <attribute name="mention_type" value="name"/>
     </mention_ref>
          <mention_ref equiv_id="_473" head="816" id="_336" name="AP" norm="ap" ontology="entity:organization:company" tail="818" type="mention">
          <attribute name="confidence" value="2"/>
          <attribute name="mention_type" value="name"/>
     </mention_ref>
          <mention_ref equiv_id="_473" head="475" id="_332" name="Associated Press" norm="associated_press" ontology="entity:organization:company" tail="491" type="mention">
          <attribute name="confidence" value="4"/>
          <attribute name="mention_type" value="name"/>
     </mention_ref>
          <mention_ref equiv_id="_473" head="2326" id="_472" name="The Associated Press" norm="the_associated_press" ontology="entity:organization:company" tail="2346" type="mention">
          <attribute name="mention_type" value="extended_name"/>
     </mention_ref>
          <mention_ref equiv_id="_473" head="471" id="_470" name="The Associated Press" norm="the_associated_press" ontology="entity:organization:company" tail="491" type="mention">
          <attribute name="mention_type" value="extended_name"/>
     </mention_ref>
          <attribute name="confidence" value="4"/>
          <attribute name="confidence" value="2"/>
          <attribute head="2326" name="extended_name" tail="2346" value="The Associated Press"/>
          <attribute head="471" name="extended_name" tail="491" value="The Associated Press"/>
          <attribute name="mention_type" value="name"/>
          <attribute name="mention_type" value="extended_name"/>
          <attribute head="2330" name="name" tail="2346" value="Associated Press"/>
          <attribute head="1557" name="name" tail="1559" value="AP"/>
          <attribute head="816" name="name" tail="818" value="AP"/>
          <attribute head="475" name="name" tail="491" value="Associated Press"/>
     </item>it is valid, but not formatted.

Similar Messages

  • Formatting  XML file to avoid mapping parser error

    Hi,
    We have requirement in our project to process input xml file which is of the below format:
    <message>
    <data>
    <xml version=1.0 code=utf/>
    <test>
    <data>book</data>
    </test>
    </data></message>
    Since <xml>  tag is at the middle it is throwing a exception error in mapping.
    Actual requirment is that we need
    <test>
    <data>book</data>
    </test>
    The xml of the above format is generated by some external system which PI  need to pick it.
    I think  is not possible in XSLT mapping as it is not starting with xml tag .
    So please let me know pointer ot resolve the issue.
    Thanks in advance.

    Hi Yeshwanth,
    If this input XML. Then it is valid XML.
    <message>
      <data>
        <xml version="1.0" code="utf" />
        <test>
          <data>book</data>
        </test>
      </data>
    </message>
    Please paste the error message, input and expected output XML.
    Regards,
    Raghu_Vamsee
    Edited by: Raghu Vamsee on Aug 25, 2011 12:10 PM

  • Data in XML format (XML files) to BW?

    Hi,
    My customer is interested in loading data to BW (from 3rd party system) in XML format. Are there any advantages of doing this (compared to traditional ascii files)? How about disadvantages (BW version is 3.5) ?. How to get started with this one, I noticed there is a possibility to create a XML data source. Is this able to take XML files into BW or what?.
    Any help highly appreciated!

    Hi Jimmy,
       Have a look:
    http://help.sap.com/saphelp_nw04/helpdata/en/9b/821140d72dc442e10000000a1550b0/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/55/014e3c97f6bb3ee10000000a114084/content.htm
    Hope it Helps
    Srini

  • Stepping through a poorly formatted xml file

    Hi, this forum worked a charm earlier so I'm hoping it will go 2 for 2.
    Through a httpservice I'm reading an XML file into a ArrayCollection. Because the XML is so poorly formatted I'm having to write some very sloppy code just to step through 20 results. I have no control over the XML.
    XML Example (can be anywhere from 0 to 20 results):
    <results>
        <game>
            <type>game</type>
            <id>321</id>
            <name>gamename</name>
            <image>i34d.png</image>
        </game>
        <character>
            <type>character</type>
            <id>1123</id>
            <name>john</name>
            <image>sds.png/image>
        </character>
        <game>
            <type>game</type>
            <id>432</id>
            <name>examplename</name>
            <image>g2dss.png</image>
        </game>
    </results>
    Each result can be one of 7 types (I've done only 2, game and character, in my example). The order of them I really want to preserve in my ArrayCollection as it's very relevant.
    Here is the (very) sloppy way I'm currently loading each result into my AC:
    //container array
    var ac2:ArrayCollection = new ArrayCollection;
    //I do a block like this for EVERY results type. Meaning 7 in total...
    if (service2.lastResult.response.results.character) {
         var characterAC:ArrayCollection = new ArrayCollection;
         if (service2.lastResult.response.results.character is ArrayCollection) {
         //there is more than 1 entry
         characterAC = service2.lastResult.response.results.character as ArrayCollection;
         } else {
              //There is only 1 entry. Need to MAKE it an ArrayColleciton
              characterAC = new ArrayCollection([service2.lastResult.response.results.character]);
            //Add all characters to AC
         ac2.addAll(characterAC);
    The two major problems with this code is: 1, it's stupidly bloated and 2, ac2 no longer maintains the order of the XML response. First it puts all <character> into my AC, then it puts all <game> into AC. So on and so forth.
    In my head I'm trying to do something like this:
    ac2 = service2.lastResult.response.results.* as ArrayCollection;
    That would then load all results (regardless of type) into an ArrayCollection. I'm guessing a solution is not that simple...
    In an Ideal world, whoever created the XML api would just call each result <result> instead of the stupid type tags it currently uses.
    I hope all that makes sense.
    Regards,
    Zaph.

    @Zaph31,
    Why not use an XMLListCollection instead of an ArrayCollection?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init();">
        <mx:XML id="iWouldntHaveCodedXMLLikeThat" xmlns="">
            <results>
                <game>
                    <type>game</type>
                    <id>321</id>
                    <name>gamename</name>
                    <image>i34d.png</image>
                </game>
                <character>
                    <type>character</type>
                    <id>1123</id>
                    <name>john</name>
                    <image>sds.png</image>
                </character>
                <game>
                    <type>game</type>
                    <id>432</id>
                    <name>examplename</name>
                    <image>g2dss.png</image>
                </game>
            </results>
        </mx:XML>
        <mx:XMLListCollection id="xmlListColl" />
        <mx:Script>
            <![CDATA[
                private function init():void {
                    xmlListColl.source = iWouldntHaveCodedXMLLikeThat.children();
            ]]>
        </mx:Script>
        <mx:DataGrid id="dg" dataProvider="{xmlListColl}">
            <mx:columns>
                <mx:DataGridColumn dataField="type" />
                <mx:DataGridColumn dataField="id" />
                <mx:DataGridColumn dataField="name" />
                <mx:DataGridColumn dataField="image" />
            </mx:columns>
        </mx:DataGrid>
    </mx:Application>
    Peter

  • Document to formatted XML file

    I have a question. I have written a sample java program that will create an xml file. The program works properly, but the generated xml is not formatted. How can i format the xml file.
    The java program code is
    package com.spi.xml;
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    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 WriteXML {
    static Document document;
    public static void buildDOM() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.newDocument();
    Element root = (Element) document.createElement("GUI");
    document.appendChild(root);
    Element curElement = document.createElement("Button");
    curElement.appendChild(document.createTextNode("Submit"));
    root.appendChild(curElement);
    curElement = document.createElement("Button");
    curElement.appendChild(document.createTextNode("Cancel"));
    root.appendChild(curElement);
    // Save the document to the disk file
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    Transformer aTransformer = tranFactory.newTransformer();
    Source src = new DOMSource(document);
    Result dest = new StreamResult(new File("C:\\xmlFileName.xml"));
    aTransformer.transform(src, dest);
    } catch (Exception pce) {
    pce.printStackTrace();
    public static void main(String[] args) {
    buildDOM();
    The output (XML file)
    <?xml version="1.0" encoding="UTF-8"?>
    <GUI><Button>Submit</Button><Button>Cancel</Button></GUI>
    How can i format the xml file for multiple lines? I cant't use other libraries (Xerces,JDOM,Xalan) cause they are to big - the application is an applet.

    I don't think the DOM stuff in the core API provides any pretty printing facilities, unless they were added in 5.0.
    I know that jdom does--http://www.jdom.org
    You might also check out apache's XML stuff--http://xml.apache.org/
    Or dom4j--http://www.dom4j.org/

  • Error parsing ERwin 7.x File when I  tried to IMPORT repository format xml file in SQl Data Modeller

    This is what i got in the log file when i tried to import a relatively large file 1.7 GB xml file
    Import Finished
    Errors:   1
    Warnings: 0
    <<<<< ERRORS >>>>>
    Error parsing ERwin 7.x File:<File path>
    Please help.

    The error information in the External log file is
    ERROR ERwinHandler - ERwinHandler - Unable to parse ERwin 7.x file: <file path>
    java.lang.OutOfMemoryError: Java heap space
      at oracle.dbtools.crest.model.ModelIDObject.<init>(ModelIDObject.java:46)
      at oracle.dbtools.crest.model.design.DesignObject.<init>(DesignObject.java:111)
      at oracle.dbtools.crest.model.design.ContainedObject.<init>(ContainedObject.java:82)
      at oracle.dbtools.crest.model.design.ContainedObjectWithDomain.<init>(ContainedObjectWithDomain.java:76)
      at oracle.dbtools.crest.model.design.relational.FKElement.<init>(FKElement.java:14)
      at oracle.dbtools.crest.model.design.relational.Column.<init>(Column.java:148)
      at oracle.dbtools.crest.model.design.relational.Table.createColumn(Table.java:432)
      at oracle.dbtools.crest.imports.erwin.ERSAXParserv7x.parseColumns(ERSAXParserv7x.java:1681)
      at oracle.dbtools.crest.imports.erwin.ERSAXParserv7x.parseEntity(ERSAXParserv7x.java:1364)
      at oracle.dbtools.crest.imports.erwin.ERSAXParserv7x.endEntitiesAndAttributes(ERSAXParserv7x.java:994)
      at oracle.dbtools.crest.imports.erwin.ERSAXParserv7x.endElement(ERSAXParserv7x.java:428)
      at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1666)
      at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:458)
      at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:404)
      at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:245)
      at oracle.xml.jaxp.JXSAXParser.parse(JXSAXParser.java:298)
      at oracle.dbtools.crest.imports.erwin.ERwinHandler.parseFile(ERwinHandler.java:252)
      at oracle.dbtools.crest.imports.erwin.ERwinHandler.access$500(ERwinHandler.java:51)
      at oracle.dbtools.crest.imports.erwin.ERwinHandler$Runner.run(ERwinHandler.java:126)
      at java.lang.Thread.run(Thread.java:745)
    2015-02-11 14:38:12,680 [main] INFO  ApplicationView - Oracle SQL Developer Data Modeler 4.1.0.866
    2015-02-11 16:13:44,218 [Thread-33] ERROR ERwinHandler - ERwinHandler - Unable to parse ERwin 7.x file: <file_Path>
    java.lang.OutOfMemoryError: Java heap space

  • How to format XML file as in JDeveloper's style?

    I'm trying to output XML by using oracle.xml.parser.v2.XMLOutputStream. There are three possible output styles: COMPACT, DEFAULT, PRETTY. I tried all of them, but none of them can give me the exact fromatting style as in JDeveloper. What output style JDeveloper is using? If there's a special XSL is being used by JDeveloper, can anyone give me a link?
    Much thanks
    Charles

    You mean you want to see the XML source?
    You need to replace the characters '<' and '&' with corresponding entities '&lt;' and '&amp;'. You can use replaceAll, but do the ampersands first.
    Then I suggest you probably want to put them in a <PRE> block.

  • Using a CWM format XML as datastore; COM SDK to read the file and create Universe

    Hello everyone
    We are in the process of migrating from a metadata store to BusinessObjects Universe and the plan is to use Java/COM SDK to accomplish that. We have run into limitations with both the SDKs. Java SDK doesn't provide that facility and using COM SDK we are trying to read from a XML file (metadata in CWM format) and create the universe but so far haven't been successful. If the (Universe)Designer can read a CWM format xml file (say created from BODS) we are wondering why can't a customer made COM program do the same.
    Has anyone attempted this and been successful. Please acknowledge.
    Thanks

    I have written C#.NET code to build universes on the fly using the Designer SDK with no problems.  However, I wasn't using CWM formatted data to do this.
    I have two suggestions for you:
    1.  Since not all of the functionality in the Designer tool seems to be available through the SDK, can you parse the CWM xml file in your code and build the universe based on the data instead of trying have Designer build it?
    2.  Since you're using Java, you may get better answers by posting this question in the Java SDK Application Development space here:  http://scn.sap.com/community/bi-platform/java-sdk
    -Dell

  • Convert data from internal table to XML file.

    Hi All,
    I am selecting data from database into one internal table.
    Now I want to convert data from internal table to xml file format and save in to my desktop. Please suggest me how I can achieve my requirement.
    Kindly reply me ASAP.

    Use this FM. SAP_CONVERT_TO_XML_FORMAT
    Check this link too -
    Re: Data Export in XML format
    XML files from ABAP programs

  • Do you have examples of CSV Format XML that can handle relationshiptypes?

    Hi,
    I have created a Windows Computer extended class that, for the sake of the example, has an additional property
    ServerNameRow , and a relationship (selected via Single Instance Picker control)
    BusinessUnitCustomersListPickerClass_Relationship. (The Single Instance Picker selects the primary name field/property only)
    I want to import data via CSV, and/or PowerShell. Both need a Format XML file.
    I don't know what the syntax is for relationship BusinessUnitCustomersListPickerClass_Relationship.
    What I'd need is some examples, preferably of a non-extended class and of an extended class's format XML.

    http://blogs.technet.com/b/servicemanager/archive/2009/05/26/using-the-csv-import-feature.aspx
    At the bottom of that blog post is an attachment (CSVImport.docx). It contains all the information you'll need for constructing CSV imports, including examples.
    To import relationships, you'll need to define a type projection targeting the windows computer class that contains a component for your custom relationship type.
    Also note you should not use the extension class itself in your definition file or in the type projection definition. Just use the windows computer class. Don't worry..your extension class property will be recognized by the import process. Extensions
    to a class are different than inherited classes.

  • Simple XML import via url (not xml file, rather xml stream)?

    Looking to solve this issue: have a web-based application and need to populate form with data in order to generate custom report. Understand I can create an xml file and have the pdf read this file. Want to avoid creation of file and get data directly from url (e.g. https://myserver/list/widgets/format/xml - this request will return the xml). I can do this in Flash by specifying a url as opposed to a flat file when importing data. Does LiveCycle offer the same feature?
    Appreciate your time and responses!

    Richard,
    I guess a link or shortcut won't do the trick as it is still pointing to the actual file that is stored in the repository that is enabled in the xmlforms_filter....
    What might be worth trying is to create 2 new File System repositories that point to the same File System.
    For example: fsr_xml_plain and fsr_xml_fancy point to lets say  Windows: C:/my/test/folder or Unix: /my/test/folder...
    Then you add the repository fsr_xml_fancy to the xmlforms_filter and you leave fsr_xml_plain out of it.
    Now if you call https://server.url.com:50100/irj/go/km/docs/fsr_xml_fancy/file.xml then you get the formatted xml file
    and if you call https://server.url.com:50100/irj/go/km/docs/fsr_xml_plain/file.xml then you get the unformatted plain xlm file
    I don't know if above works as I don't have the time to validate it for you at this moment.
    Good Luck,
    Benjamin Houttuin

  • XML file error

    HI im writing elements to an xml file created from scratch.
    here is the pertinent code that creates the structure
    //First i create the root element
    public void addRootNodeToDocument(Document doc, String componentName) {
    try {
         rootElement = doc.createElement(componentName);
    }catch...then these few lines of code are called repeatedly to add a child onto a parent.
    I get the parent node from a map, and add a child element onto it.
    Element parentElement = (Element) elementMap.get(parentString);
    Element childElement = doc.createElement(componentName);
    parentElement.appendChild(childElement);then i call these few lines of code to write to the xml file:
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    //transform the DOM tree to output XML file.
    transformer.transform(new DOMSource(doc), new StreamResult(new FileOutputStream("testfile.xml")));when i try to open the xml file i get this error
    XML document must have a top level element. Error processing resource and all thats been written to the xml file is:
    <?xml version="1.0" encoding="UTF-8"?>has anyone any idea why this is occuring?
    many thanks.

    rootElement = doc.createElement(componentName);
    doesn't actually set the root element, you need to do
    doc.appendChild(rootElement);
    afterwards

  • Reading the Blob and writing it to an external file in an xml tree format

    Hi,
    We have a table by name clarity_response_log and content of the column(Response_file) is BLOB and we have xml file or xml content in that column. Most probably the column or table may be having more than 5 records and hence we need to read the corresponding blob content and write to an external file.
    CREATE TABLE CLARITY_RESPONSE_LOG
      REQUEST_CODE   NUMBER,
      RESPONSE_FILE  BLOB,
      DATE_CRATED    DATE                           NOT NULL,
      CREATED_BY     NUMBER                         NOT NULL,
      UPDATED_BY     NUMBER                         DEFAULT 1,
      DATE_UPDATED   VARCHAR2(20 BYTE)              DEFAULT SYSDATE
    )The xml content in the insert statement is very small because of some reason and cannot be made public and indeed we have a very big xml file stored in the BLOB column or Response_File column
    Insert into CLARITY_RESPONSE_LOG
       (REQUEST_CODE, RESPONSE_FILE, DATE_CRATED, CREATED_BY, UPDATED_BY, DATE_UPDATED)
    Values
       (5, '<?xml version="1.0" encoding="UTF-8"?><xml-response><phone-number>1212121212</tracking-number></xml-response>', TO_DATE('09/23/2010 09:01:34', 'MM/DD/YYYY HH24:MI:SS'), 1, 1, '23-SEP-10');
    Insert into CLARITY_RESPONSE_LOG
       (REQUEST_CODE, RESPONSE_FILE, DATE_CRATED, CREATED_BY, UPDATED_BY, DATE_UPDATED)
    Values
       (6, '<?xml version="1.0" encoding="UTF-8"?><xml-response><phone-number>1212121212</tracking-number></xml-response>', TO_DATE('09/23/2010 09:01:34', 'MM/DD/YYYY HH24:MI:SS'), 1, 1, '23-SEP-10');
    Insert into CLARITY_RESPONSE_LOG
       (REQUEST_CODE, RESPONSE_FILE, DATE_CRATED, CREATED_BY, UPDATED_BY, DATE_UPDATED)
    Values
       (7, '<?xml version="1.0" encoding="UTF-8"?><xml-response><phone-number>1212121212</tracking-number></xml-response>', TO_DATE('09/23/2010 09:01:34', 'MM/DD/YYYY HH24:MI:SS'), 1, 1, '23-SEP-10');
    Insert into CLARITY_RESPONSE_LOG
       (REQUEST_CODE, RESPONSE_FILE, DATE_CRATED, CREATED_BY, UPDATED_BY, DATE_UPDATED)
    Values
       (8, '<?xml version="1.0" encoding="UTF-8"?><xml-response><phone-number>1212121212</tracking-number></xml-response>', TO_DATE('09/23/2010 09:01:34', 'MM/DD/YYYY HH24:MI:SS'), 1, 1, '23-SEP-10');
    Insert into CLARITY_RESPONSE_LOG
       (REQUEST_CODE, RESPONSE_FILE, DATE_CRATED, CREATED_BY, UPDATED_BY, DATE_UPDATED)
    Values
       (9, '<?xml version="1.0" encoding="UTF-8"?><xml-response><phone-number>1212121212</tracking-number></xml-response>', TO_DATE('09/23/2010 09:01:34', 'MM/DD/YYYY HH24:MI:SS'), 1, 1, '23-SEP-10');THe corresponding proc for reading the data and writing the data to an external file goes something like this
    SET serveroutput ON
    DECLARE
       vstart     NUMBER             := 1;
       bytelen    NUMBER             := 32000;
       len        NUMBER;
       my_vr      RAW (32000);
       x          NUMBER;
       l_output   UTL_FILE.FILE_TYPE;
    BEGIN
    -- define output directory
       l_output :=
          UTL_FILE.FOPEN ('CWFSTORE_RESPONCE_XML', 'extract500.txt', 'wb', 32760);
       vstart := 1;
       bytelen := 32000;
    ---get the Blob locator
       FOR rec IN (SELECT response_file vblob
                     FROM clarity_response_log
                    WHERE TRUNC (date_crated) = TRUNC (SYSDATE - 1))
       LOOP
    --get length of the blob
    len := DBMS_LOB.getlength (rec.vblob);
          DBMS_OUTPUT.PUT_LINE (len);
          x := len;
    ---- If small enough for a single write
    IF len < 32760
          THEN
             UTL_FILE.put_raw (l_output, rec.vblob);
             UTL_FILE.FFLUSH (l_output);
          ELSE  
    -------- write in pieces
             vstart := 1;
             WHILE vstart < len AND bytelen > 0
             LOOP
                DBMS_LOB.READ (rec.vblob, bytelen, vstart, my_vr);
                UTL_FILE.put_raw (l_output, my_vr);
                UTL_FILE.FFLUSH (l_output);
    ---------------- set the start position for the next cut
                vstart := vstart + bytelen;
    ---------- set the end position if less than 32000 bytes
                x := x - bytelen;
                IF x < 32000
                THEN
                   bytelen := x;
                END IF;
                UTL_FILE.NEW_LINE (l_output);
             END LOOP;
    ----------------- --- UTL_FILE.NEW_LINE(l_output);
          END IF;
       END LOOP;
       UTL_FILE.FCLOSE (l_output);
    END;The above code works well and all the records or xml contents are being written simultaneously adjacent to each other but we each records must be written to a new line or there must be a line gap or a blank line between any two records
    the code which I get is as follow all all xml data comes on a single line
    <?xml version="1.0" encoding="ISO-8859-1"?><emp><empno>7369</empno><ename>James</ename><job>Manager</job><salary>1000</salary></emp><?xml version="1.0" encoding="ISO-8859-1"?><emp><empno>7370</empno><ename>charles</ename><job>President</job><salary>500</salary></emp>But the code written to an external file has to be something like this.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <emp>
      <empno>7369</empno>
      <ename>James</ename>
      <job>Manager</job>
      <salary>1000</salary>
    </emp>
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <emp>
    <empno>7370</empno>
    <ename>charles</ename>
    <job>President</job>
    <salary>500</salary>
    </emp>Please advice

    What was wrong with the previous answers given on your other thread:
    Export Blob data to text file(-29285-ORA-29285: file write error)
    If there's a continuing issue, stay with the same thread, don't just ask the same question again and again, it's really Pi**es people off and causes confusion as not everyone will be familiar with what answers you've already had. You're just wasting people's time by doing that.
    As already mentioned before, convert your BLOB to a CLOB and then to XMLTYPE where it can be treated as XML and written out to file in a variety of ways including the way I showed you on the other thread.
    You really seem to be struggling to get the worst possible way to work.

  • Format XML data when writing to a file

    Hi,
    I am trying to write runtime data (XML) to a file. I am doign the following to write to the file:
    public void saveFile() throws Exception {
    try {
    TransformerFactory transformerFactory =
    TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    OutputStream output = new FileOutputStream(XMLFile);
    StreamResult result = new StreamResult();
    transformer.transform(source, result);
    output.flush();
    output.close();
    } catch (Exception x) {
    throw x;
    The output from the above code is a clutter of elements. All the elements are on the same line some times.
    1) How can I format the output? (Indent the elements in the file)
    Is there a way to achieve this?
    Sometimes, I see a square character at the end of some lines. I thought the output file is corrupt because of this character. But it does not seem to be a problem.
    2) How do I avoid this character?

    Also, I am planning on using xpath in conjunction with DOM. However I read on one of the websites not to use too many xpath queries. I am using jdk 1.5.
    Is it tight. My code might have to be run many times. Is the following ok?
    or should I eliminate xpath and do my own traversing. I am concerned about runtime performance if I have to continue to update the xml file frequently.
    public Element getMatchingNode(MyAttributes attr) throws Exception {
    try {
    File myFile = new File(XMLFile);
    if (myFile.exists()) {
    System.out.println(XMLFile + " File exists");
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();
    InputSource inputSource =
    new InputSource(new FileInputStream(myFile));
    String matchingString = this.getMatchingString(attr);
    Element module =
    (Element)xPath.evaluate("/" + TEST_TAG +
    "/" +
    TEST_TAG2 +
    "/" +
    DETAIL +
    matchingString,
    inputSource,
    XPathConstants.NODE);
    return module;
    } else
    return null;
    } catch (Exception x) {
    throw x;
    private String getMatchingString(MyAttributes attrs){
    StringBuffer buffer = new StringBuffer();
    for (Enumeration e=attrs.keys(); e.hasMoreElements();){
    String attribute = (String)e.nextElement();
    String value = attrs.get(attribute);
    buffer.append("[@" + attribute + "=" + "'" + value + "']");
    return buffer.toString();
    }

  • "PLS-00172: string literal too long" When Writing XML file into a Table

    Hi.
    I'm using DBMS_XMLStore to get a XML file into a db table. See the example below, I'm using that for my PL/SQL format. Problem is that because there're too many XML elements that I use in "xmldoc CLOB:= ...", I get "PLS-00172: string literal too long" error.
    Can someone suggest a workaround?
    THANKS!!!
    DECLARE
    insCtx DBMS_XMLStore.ctxType;
    rows NUMBER;
    xmldoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <EMPNO>7369</EMPNO>
    <SAL>1800</SAL>
    <HIREDATE>27-AUG-1996</HIREDATE>
    </ROW>
    <ROW>
    <EMPNO>2290</EMPNO>
    <SAL>2000</SAL>
    <HIREDATE>31-DEC-1992</HIREDATE>
    </ROW>
    </ROWSET>';
    BEGIN
    insCtx := DBMS_XMLStore.newContext('scott.emp'); -- get saved context
    DBMS_XMLStore.clearUpdateColumnList(insCtx); -- clear the update settings
    -- set the columns to be updated as a list of values
    DBMS_XMLStore.setUpdateColumn(insCtx,'EMPNO');
    DBMS_XMLStore.setUpdateColumn(insCtx,'SAL');
    DBMS_XMLStore.setUpdatecolumn(insCtx,'HIREDATE');
    -- Now insert the doc.
    -- This will only insert into EMPNO, SAL and HIREDATE columns
    rows := DBMS_XMLStore.insertXML(insCtx, xmlDoc);
    -- Close the context
    DBMS_XMLStore.closeContext(insCtx);
    END;
    /

    You ask where am getting the XML doc. Well, am not
    getting the doc itself.I either don't understand or I disagree. In your sample code, you're certainly creating an XML document-- your local variable "xmldoc" is an XML document.
    DBMS_XMLSTORE package needs
    to know the canonical format and that's what I
    hardcoded. Again, I either don't understand or I disagree... DBMS_XMLStore more or less assumes the format of the XML document itself-- there's a ROWSET tag, a ROW tag, and a then whatever column tags you'd like. You can override what tag identifies a row, but the rest is pretty much assumed. Your calls to setUpdateColumn identifies what subset of column tags in the XML document you're interested in.
    Later in code I use
    DBMS_XMLStore.setUpdateColumn to specify which
    columns are to be inserted.Agreed.
    xmldoc CLOB :=
    '<ROWSET>
    <ROW num="1">
    <KEY_OLD> Smoker </KEY_OLD>
    <KEY_NEW> 3 </KEY_NEW>
    <TRANSFORM> Specified </TRANSFORM>
    <KEY_OLD> Smoker </KEY_OLD>
    <VALUEOLD> -1 </VALUEOLD>
    EW> -1 </VALUENEW>
         <DESCRIPTION> NA </DESCRIPTION>
    </ROW>
    ROWSET>';This is your XML document. You almost certainly want to be reading this from the file system and/or have it passed in from another procedure. If you hard-code the XML document, you're limited to a 32k string literal, which is almost certainly causing the error you were reporting initially.
    As am writing this I'm realizing that I'm doing this
    wrong, because I do need to read the XML file from
    the filesystem (but insert the columns
    selectively)...What I need to come up with is a proc
    that would grab the XML file and do inserts into a
    relational table. The XML file will change in the
    future and that means that all my 'canonical format'
    code will be broken. How do I deal with anticipated
    change? Do I need to define/create an XML schema in
    10g if am just inserting into one relat. table from
    one XML file?What does "The XML file will change in the future" mean? Are you saying that the structure of the XML document will change? Or that the data in the XML document would change? Your code should only need to change if the structure of the document changes, which should be exceptionally uncommon and would only be an issue if you're adding another column that you want to work with, which would necessitate code changes.
    I found an article where the issue of changing XML
    file is dealt by using a XSL file (that's where I'd
    define the 'canonical format'), but am having a
    problem with creating one, because the source XML is
    screwed up in terms of the format:
    it's not <x> blah </x>
    <x2> blah </x2>
    x2="blah" x3="blah> ...etc
    Can you point me in the right direction, please?You can certainly use something like the DBMS_XSLProcessor package to transform whatever XML document you have into an XML document in an appropriate format for the XMLStore package and pass that transformed XML document into something like your sample procedure rather than defining the xmldoc local variable with a hard-coded document. Of course, you'd need to write appropriate XSL code to do the actual transform.
    Justin

Maybe you are looking for