Pretty printing xml with sql

Hello
I have to pretty print xml which is stored in data base column ( clob)
My table
create table mytab
myxml clob);mydata
<?xml version="1.0" encoding="ISO-8859-1"?>
<Us name="Step">
<my name ="st">
<colol name="t"/>
</my>
</Us>any idea/suggestion?
Edited by: user10647455 on Dec 19, 2011 2:04 PM

Thanks !
I tired this as well
select XMLSerialize( document xmltype(myxml) as CLOB INDENT ) from mytab;

Similar Messages

  • How to pretty print XML alerts

    Hi!
    I'd like to generate mail alerts in OSB which include a XML content. I need XML to be human friendly printed (that is with indentation) but XML is printed in a single line.
    Is there any way to pretty print XML content in alerts (and also in alerts emails).
    Thank you in advance.

    The example of what the OP wants it to look like I thought was quite plain. Its right at the top of the post.
    Unfortunately it is also quite difficult to accomplish using System.out.print statements.
    You have to print out the root of the tree first (its at the top)
    However you don't know how far along to the right you need to print it without traversing the child nodes already (you need to know how deep the tree is, and how far to the left the tree extends from the root)
    So you will need to traverse the tree at least twice.
    Once to work out the offsets, and again to print out the values.
    The working out of offsets would have to be a depth search traversal I think
    The printing of the values in this fashion would be a breadth first traversal.
    I remember (ages ago) doing a similar assignment, except we printed the tree sideways.
    ie the root was on the left, the leaves of the tree on the right of the screen.
    That meant you could do an inorder depth traversal of the tree to just print it once.
    hope this helps,
    evnafets

  • Pretty-print xml

    Anybody has any idea how can I do a pretty-print of an xml which is stored in the oracle database as CLOB.
    I tried LSSerializer, but could not get it work. I am using jdeveloper10.1.2
    Thanks
    MM

    Have you tried this:
    StringWriter sw = new StringWriter();
    org.apache.xml.serialize.OutputFormat outFormat = new org.apache.xml.
    serialize.OutputFormat();
    outFormat.setIndenting(true);
    outFormat.setIndent(4);
    org.apache.xml.serialize.XMLSerializer xmlser = new org.apache.xml.serialize.XMLSerializer(sw, outFormat);
    try {
    xmlser.serialize(your_document); //replace your_document with reference to document you want to serialize
    catch (Exception ex1) {
    }

  • Really no way to pretty print XML???

    I wonder if there is really no way to pretty print a DOM, using Java's standard API (http://java.sun.com/j2se/1.4.2/docs/api/index.html).
    What I've tried is (assume having a org.w3c.dom.Document instance doc:
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty("encoding", encoding);
    transformer.setOutputProperty(OutputKeys.INDENT,"yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3" );
    DOMSource source = new DOMSource(doc);
    FileOutputStream os = new FileOutputStream(file);
    StreamResult result = new StreamResult(os);
    transformer.transform(source,result);which gives, e.g. something like
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <documentData>
    <Asset assetID="229609"/>
       <Picturedescription>
    <Asset assetID="229609"/>
    </Picturedescription>
    </documentData>which is not even proper indent. I can't believe that there is no way in pretty prenting an XML document, using Java's Standard API....
    Does anybody know more about it?
    Urs

    Have you tried this:
    StringWriter sw = new StringWriter();
    org.apache.xml.serialize.OutputFormat outFormat = new org.apache.xml.
    serialize.OutputFormat();
    outFormat.setIndenting(true);
    outFormat.setIndent(4);
    org.apache.xml.serialize.XMLSerializer xmlser = new org.apache.xml.serialize.XMLSerializer(sw, outFormat);
    try {
    xmlser.serialize(your_document); //replace your_document with reference to document you want to serialize
    catch (Exception ex1) {
    }

  • How can I load this XML with sql loader ?

    Hi,
    Im try to load a XML file into a XML table:
    Create table TEST of XMLTYPE;
    XML file is something like this:
    <!DOCTYPE list SYSTEM "myfile.dtd">
    <list>
    <item id = 1> lot of tags an info here </item>
    <item id = 9000> lot of tags an info here </item>
    </list>
    I dont know how to exactly create an appropriate control file to my XML. All examples I saw in documentation are similar to this one:
    this is an example control file
    LOAD DATA
    INFILE *
    INTO TABLE test
    APPEND
    XMLTYPE (xmldata)
    FIELDS
    I dont know how to complete this control file. Can anyone help me ?
    thank you!
    Message was edited by:
    pollopolea

    Well I found this working code
    LOAD DATA
    INFILE *
    INTO TABLE test APPEND
    xmltype(xmldata)
    FIELDS
    ext_fname filler char(30),
    xmldata LOBFILE (ext_fname) TERMINATED BY EOF
    BEGINDATA
    mifile.xml
    mifile2.xml
    mifile3.xml
    the main diference I found is that when i use:
    Insert into test values (XMLType(bfilename('XMLDIR', 'swd_uC000025127.xml'),nls_charset_id('AL32UTF8')));
    tag <!DOCTYPE list SYSTEM "myfile.dtd"> is expanded
    (I explain at DTD insertion and errors with long DTD entities
    Now using sql loader the tag is not modified.
    I dont know if is there any difference, between each case. did I lost performance?
    Message was edited by:
    pollopolea

  • How to load XML file to table (non-XML) with SQL*Loader -- issue with nulls

    I have been attempting to use SQL*Loader to load an XML file into a "regular" Oracle table. All fields work fine, unless a null is encountered. The way that nulls are represented is shown below:
    <PAYLOAD>
    <FIELD1>ABCDEF</FIELD1>
    <FIELD2/>
    <FIELD3>123456</FIELD3>
    </PAYLOAD>
    In the above example, FIELD2 is a null field and that is the way it is presented. I have searched everywhere and have not found how I could code for this. The issue is that if FIELD2 is present, it is coded like: <FIELD2>SOMEDATA</FIELD2>, but the null is represented as <FIELD2/>. Here is a sample of the control file I am using to attempt the load -- very simplistic, but works fine when fields are present:
    load data
    infile 'testdata.xml' "str '<PAYLOAD>'"
    TRUNCATE
    into table DATA_FROM_XML
    FIELD1 ENCLOSED BY '<FIELD1>' AND '</FIELD1>',
    FIELD2 ENCLOSED BY '<FIELD2>' AND '</FIELD2>',
    FIELD3 ENCLOSED BY '<FIELD3>' AND '</FIELD3>')
    What do I need to do to account for the way that nulls are presented? I have tried everything I could glean from the web and the documentation and nothing has worked. Any help would be really appreciated.

    I hadn't even got that far. can you direct me to where the docs are to import data that is stored within xml but that you don't need any xml functionality, that just happens to be the format the data is stored in? thx

  • Xml  with sql loader

    Hi,
    i tried to load the xml datas into database using sql loader.
    CREATE DIRECTORY xml_dir AS '/:';
    GRANT READ ON DIRECTORY xml_dir TO wiki;
    xml.ctl
    OPTIONS (ERRORS=100, SILENT=(FEEDBACK))
    LOAD DATA
    INFILE 'emp.xml'
    APPEND
    INTO TABLE emp
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    (empno,ename,job,mgr,hiredate,sal,comm,deptno)
    *emp.xml*
    <name>
    <empno>1</empno>
    <ename>1</ename>
    <job>1</job>
    <mgr>1</mgr>
    <hiredate></hiredate>
    <sal>1</sal>
    <comm>1</comm>
    <deptno>1</deptno>
    </name>
    i got the following errors in log
    Record 1: Rejected - Error on table EMP, column ENAME.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 2: Rejected - Error on table EMP, column ENAME.
    how to the sql*loader identify seperator in xml file.
    please help me out that.

    Hi,
    i tried to load the xml datas into database using sql loader.
    CREATE DIRECTORY xml_dir AS '/:';
    GRANT READ ON DIRECTORY xml_dir TO wiki;
    xml.ctl
    OPTIONS (ERRORS=100, SILENT=(FEEDBACK))
    LOAD DATA
    INFILE 'emp.xml'
    APPEND
    INTO TABLE emp
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    (empno,ename,job,mgr,hiredate,sal,comm,deptno)
    *emp.xml*
    <name>
    <empno>1</empno>
    <ename>1</ename>
    <job>1</job>
    <mgr>1</mgr>
    <hiredate></hiredate>
    <sal>1</sal>
    <comm>1</comm>
    <deptno>1</deptno>
    </name>
    i got the following errors in log
    Record 1: Rejected - Error on table EMP, column ENAME.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 2: Rejected - Error on table EMP, column ENAME.
    how to the sql*loader identify seperator in xml file.
    please help me out that.

  • Printing XML with attributes

    Hi,
    I wrote some code to generate DOM trees, and some more code to print a tree as a string.
    But my the string loses attributes - i.e. all tags come out without attributes. And I am not sure why....
    public static String getStringXml(Document xmlDoc)
              //Output the XML to string
              TransformerFactory fac = TransformerFactory.newInstance();
              Transformer transformer = null;
              StringWriter writer = new StringWriter();
              try
                   transformer = fac.newTransformer();
                   transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                   StreamResult result = new StreamResult(writer );
                   DOMSource source = new DOMSource(xmlDoc);
                   transformer.transform(source, result);
              catch (TransformerConfigurationException e)
                   e.printStackTrace();
              catch (TransformerException e)
                   e.printStackTrace();
              return writer.toString();
         }

    It is possible I am doing something wrong when adding attriubtes:
    Element myElement = xmlDoc.createElement("myElement");
    myElement.setAttribute("id", "first");

  • Load XML with SQL*Loader

    Goodmorning,
    I have this XML file:
    bq. &lt;?xml version="1.0"?&gt; \\     &lt;Header&gt; \\     &lt;DocName&gt;NOMRES&lt;/DocName&gt; \\     &lt;DocVersion&gt;3.2&lt;/DocVersion&gt; \\     &lt;Sender&gt;TIGF&lt;/Sender&gt; \\     &lt;Receiver&gt;TIENIG&lt;/Receiver&gt; \\     &lt;DocNumber&gt;120731&lt;/DocNumber&gt; \\     &lt;DocDate&gt;2008-12-14T16:36:43.9288481+01:00&lt;/DocDate&gt; \\     &lt;DocType&gt;J&lt;/DocType&gt; \\     &lt;Contract&gt;TIGF-TIENIG&lt;/Contract&gt; \\     &lt;/Header&gt; \\     &lt;ListOfGasDays&gt; \\     &lt;GasDay&gt; \\     &lt;Day&gt;2008-12-15&lt;/Day&gt; \\     &lt;BusinessRuleFlag&gt;Processed by adjacent TSO&lt;/BusinessRuleFlag&gt; \\     &lt;ListOfLibri&gt; \\     &lt;Libro&gt; \\     &lt;Logid&gt;62&lt;/Logid&gt; \\     &lt;Isbn&gt;88-251-7194-3&lt;/Isbn&gt; \\     &lt;Autore&gt;Elisa Bertino&lt;/Autore&gt; \\     &lt;Titolo&gt;Sistemi di basi di dati - Concetti e architetture&lt;/Titolo&gt; \\     &lt;Anno&gt;1997&lt;/Anno&gt; \\     &lt;Collocazione&gt;Dentro&lt;/Collocazione&gt; \\     &lt;Genere&gt;Informatica&lt;/Genere&gt; \\     &lt;Lingua&gt;Italiano&lt;/Lingua&gt; \\     &lt;/Libro&gt; \\     &lt;Libro&gt; \\     &lt;Logid&gt;63&lt;/Logid&gt; \\     &lt;Isbn&gt;978-88-04-56981-7&lt;/Isbn&gt; \\     &lt;Autore&gt;Dan Brown&lt;/Autore&gt; \\     &lt;Titolo&gt;Crypto&lt;/Titolo&gt; \\     &lt;Anno&gt;1998&lt;/Anno&gt; \\     &lt;Collocazione&gt;Dentro&lt;/Collocazione&gt; \\     &lt;Genere&gt;Thriller&lt;/Genere&gt; \\     &lt;Lingua&gt;Italiano&lt;/Lingua&gt; \\     &lt;/Libro&gt; \\     &lt;/ListOfLibri&gt; \\     &lt;/GasDay&gt; \\     &lt;GasDay&gt; \\     &lt;Day&gt;2008-12-15&lt;/Day&gt; \\     &lt;BusinessRuleFlag&gt;Confirmed&lt;/BusinessRuleFlag&gt; \\     &lt;ListOfLibri&gt; \\     &lt;Libro&gt; \\     &lt;Logid&gt;64&lt;/Logid&gt; \\     &lt;Isbn&gt;978-88-6061-131-4&lt;/Isbn&gt; \\     &lt;Autore&gt;Stephen King&lt;/Autore&gt; \\     &lt;Titolo&gt;Cell&lt;/Titolo&gt; \\     &lt;Anno&gt;2006&lt;/Anno&gt; \\     &lt;Collocazione&gt;Dentro&lt;/Collocazione&gt; \\     &lt;Genere&gt;Horror&lt;/Genere&gt; \\     &lt;Lingua&gt;Italiano&lt;/Lingua&gt; \\     &lt;/Libro&gt; \\     &lt;Libro&gt; \\     &lt;Logid&gt;65&lt;/Logid&gt; \\     &lt;Isbn&gt;1-56592-697-8&lt;/Isbn&gt; \\     &lt;Autore&gt;David C. Kreines&lt;/Autore&gt; \\     &lt;Titolo&gt;Oracle SQL - The Essential Reference&lt;/Titolo&gt; \\     &lt;Anno&gt;2000&lt;/Anno&gt; \\     &lt;Collocazione&gt;Dentro&lt;/Collocazione&gt; \\     &lt;Genere&gt;Informatica&lt;/Genere&gt; \\     &lt;Lingua&gt;Inglese&lt;/Lingua&gt; \\     &lt;/Libro&gt; \\     &lt;Libro&gt; \\     &lt;Logid&gt;66&lt;/Logid&gt; \\     &lt;Isbn&gt;978-88-6061-131-4&lt;/Isbn&gt; \\     &lt;Autore&gt;Stephen King&lt;/Autore&gt; \\     &lt;Titolo&gt;Cell&lt;/Titolo&gt; \\     &lt;Anno&gt;2006&lt;/Anno&gt; \\     &lt;Collocazione&gt;Dentro&lt;/Collocazione&gt; \\     &lt;Genere&gt;Horror&lt;/Genere&gt; \\     &lt;Lingua&gt;Italiano&lt;/Lingua&gt; \\     &lt;/Libro&gt; \\     &lt;/ListOfLibri&gt; \\     &lt;/GasDay&gt; \\     &lt;/ListOfGasDays&gt; \\     &lt;ListOfGeneralNotes&gt; \\     &lt;GeneralNote&gt; \\     &lt;Code&gt;100&lt;/Code&gt; \\     &lt;Message&gt;Rien a signaler&lt;/Message&gt; \\     &lt;/GeneralNote&gt; \\     &lt;/ListOfGeneralNotes&gt;
    and use this control file:
    bq. load data \\ infile "Esempio.XML" "str '&lt;/Libro&gt;'" \\ BADFILE "libri.bad" \\ DISCARDFILE "libri.dis" \\ DISCARDMAX 10000 \\ truncate \\ into table LIBRI \\ TRAILING NULLCOLS \\ ( \\ dummy filler terminated by '&lt;Libro&gt;', \\ Logid enclosed by "&lt;Logid&gt;" and "&lt;/Logid&gt;", \\ Isbn enclosed by "&lt;Isbn&gt;" and "&lt;/Isbn&gt;", \\ Autore enclosed by "&lt;Autore&gt;" and "&lt;/Autore&gt;", \\ Titolo enclosed by "&lt;Titolo&gt;" and "&lt;/Titolo&gt;", \\ Anno enclosed by "&lt;Anno&gt;" and "&lt;/Anno&gt;", \\ Collocazione enclosed by "&lt;Collocazione&gt;" and "&lt;/Collocazione&gt;", \\ Genere enclosed by "&lt;Genere&gt;" and "&lt;/Genere&gt;", \\ Lingua enclosed by "&lt;Lingua&gt;" and "&lt;/Lingua&gt;" \\ )
    being uploaded but I always send error in the first record.
    Someone said me why? differently if I set the control file?
    thanks

    I have the following XML data file and had the same loading issue.
    <?xml version="1.0"?>
    <Settlement_Info>
    <file_header>
    <agency_id>129</agency_id>
    <agency_form_number/>
    <omb_form_number/>
    <treasury_account_symbol/>
    <percent_of_amount>100.00</percent_of_amount>
    </file_header>
    <body_item>
    <item_header>
    <deposit_ticket_number>001296</deposit_ticket_number>
    <total_amount_of_sf215>1,318,542,280.16</total_amount_of_sf215>
    <number_of_collections>3,929</number_of_collections>
    <total_of_all_collections>1,318,542,280.16</total_of_all_collections>
    </item_header>
    <item_detail_record>
    <paygov_tx_id>FMG4</paygov_tx_id>
    <agency_tx_id>0000015901</agency_tx_id>
    <collection_amount>8,688.70</collection_amount>
    <collection_method>ACH</collection_method>
    <deposit_ticket_number>96</deposit_ticket_number>
    <settlement_date>12/15/2009</settlement_date>
    <collection_status>SETTLED</collection_status>
    <submitter_name>MORRIS</submitter_name>
    </item_detail_record>
    <item_detail_record>
    <paygov_tx_id>FMG5</paygov_tx_id>
    <agency_tx_id>0000015902</agency_tx_id>
    <collection_amount>42,198.66</collection_amount>
    <collection_method>ACH</collection_method>
    <deposit_ticket_number>001296</deposit_ticket_number>
    <settlement_date>12/15/2009</settlement_date>
    <collection_status>SETTLED</collection_status>
    <submitter_name>CASTLE</submitter_name>
    </item_detail_record>
    <item_detail_record>
    <paygov_tx_id>4FMG6</paygov_tx_id>
    <agency_tx_id>0000015903</agency_tx_id>
    <collection_amount>57,278.25</collection_amount>
    <collection_method>ACH</collection_method>
    <deposit_ticket_number>001296</deposit_ticket_number>
    <settlement_date>12/15/2009</settlement_date>
    <collection_status>SETTLED</collection_status>
    <submitter_name>FRANKLIN</submitter_name>
    </item_detail_record>
    </body_item>
         <file_footer>
         <file_name>ACHActivityFile_12152009.xml</file_name>
         <file_creation_date>12/15/2009 10:08:31 AM</file_creation_date>
         </file_footer>
         </Settlement_Info>
    Control file
    load data
    infile 'C:\sample1.xml' "str '</item_detail_record>'"
    truncate
    into table xml_test2
    TRAILING NULLCOLS
    dummy filler terminated by "<item_detail_record>",
    paygov_tx_id enclosed by "<paygov_tx_id>" and "</paygov_tx_id>",
    agency_tx_id enclosed by "<agency_tx_id>" and "</agency_tx_id>",
    collection_amount enclosed by "<collection_amount>" and "</collection_amount>",
    collection_method enclosed by "<collection_method>" and "</collection_method>",
    deposit_ticket_number enclosed by "<deposit_ticket_number>" and "</deposit_ticket_number>",
    settlement_date enclosed by "<settlement_date>" and "</settlement_date>",
    collection_status enclosed by "<collection_status>" and "</collection_status>",
    submitter_name enclosed by "<submitter_name>" and "</submitter_name>"
    table strucutre
    CREATE TABLE XML_TEST2
    PAYGOV_TX_ID VARCHAR2(30 BYTE),
    AGENCY_TX_ID VARCHAR2(30 BYTE),
    COLLECTION_AMOUNT VARCHAR2(30 BYTE),
    COLLECTION_METHOD VARCHAR2(30 BYTE),
    DEPOSIT_TICKET_NUMBER VARCHAR2(30 BYTE),
    SETTLEMENT_DATE VARCHAR2(30 BYTE),
    COLLECTION_STATUS VARCHAR2(30 BYTE),
    SUBMITTER_NAME VARCHAR2(60 BYTE)
    If I reomove the <file_header> and <item_header> blocks, the control file works perfectly, otherwise it skips the first record.
    thanks
    Reji

  • Is there better way to do this?  (Xml Pretty Print | node removing)

    Hi all, I have been working at home on a small project to help my Java Jedi training. :-)
    My app saves quotes from authors in an xml file.
    I have a class [XmlRepository extends Thread] that holds control of an xml file to handle requests for Nodes.
    When I remove a node I get a Line Space above the node that was removed, or better put my node gets replaced by a empty line.
    Pretty print or correct Node removing.
    part of my xml is like this (I have resumed it for readability):
        <entities forUser="ffffffff-ffff-ffff-ffff-ffffffffffff">
            <quotes/>
            <authors>
                <author id="f156c570-c676-4d69-9b15-ae7d859ff771" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Poe</lastNames>
                    <firstNames>Edgar Allan</firstNames>
                </author>
                <author id="35dc0c5a-3813-4a10-af49-8d4ea1c2cee0" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Wilde</lastNames>
                    <firstNames>Oscar</firstNames>
                </author>
                <author id="317f72ea-add6-4bd2-8c63-d8b373a830ab" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Christie</lastNames>
                    <firstNames>Agatha</firstNames>
                </author>
                <author id="28047c89-b647-4c40-b6c7-677feaf2dfda" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Shakespeare</lastNames>
                    <firstNames>William</firstNames>
                </author>
            </authors>
        </entities>If I remove A Node ( Edgar Allan Poe (1st in this case)) the resulting Xml when saved is like this (I have added the space indentation just as it is outputted by my code):
        <entities forUser="ffffffff-ffff-ffff-ffff-ffffffffffff">
            <quotes/>
                <author id="35dc0c5a-3813-4a10-af49-8d4ea1c2cee0" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Wilde</lastNames>
                    <firstNames>Oscar</firstNames>
                </author>
                <author id="317f72ea-add6-4bd2-8c63-d8b373a830ab" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Christie</lastNames>
                    <firstNames>Agatha</firstNames>
                </author>
                <author id="28047c89-b647-4c40-b6c7-677feaf2dfda" languageCode="en" regenerateAs="com.fdt.cognoscere.entities.sources.Author">
                    <lastNames>Shakespeare</lastNames>
                    <firstNames>William</firstNames>
                </author>
            </authors>
        </entities>this is how I initialize the XML DOM Handlers, and the method for removing a Node:
         * Initializes factory instances and member variables.
        private void initialize() {
            //obtain an instance of a documentFactory create a document documentBuilder
            this.documentFactory = DocumentBuilderFactory.newInstance();
            //Configure the documentFactory to be name-space aware and validate trough an xsd file
            this.documentFactory.setNamespaceAware(true);
            this.documentFactory.setValidating(true);
            this.documentFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
            try {
                //obtain an instance of an XPathFactory
                this.xpathFactory = XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI);
                //obtain an instance of the xpath evaluator object
                this.xpathEvaluator = this.xpathFactory.newXPath();
                //set namespace mapping configurations
                NamespaceContextMap namespaceMappings = new NamespaceContextMap();
                namespaceMappings.put("xml", "http://www.w3.org/XML/1998/namespace");
                namespaceMappings.put("xmlns", "http://www.w3.org/2000/xmlns/");
                namespaceMappings.put("xsd", "http://www.w3.org/2001/XMLSchema");
                namespaceMappings.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
                namespaceMappings.put(this.schemaNamespaceMapping, this.schemaNamespace);
                //add mappings
                this.xpathEvaluator.setNamespaceContext(namespaceMappings);
            } catch (XPathFactoryConfigurationException ex) {
                Logger.getLogger(XmlRepository.class.getName()).log(Level.SEVERE, null, ex);
            try {
                //obtain a trasformer factory to save the file
                this.transformerFactory = TransformerFactory.newInstance();
                this.transformerFactory.setAttribute("indent-number", 4);
                //obtain the transforme
                this.transformer = this.transformerFactory.newTransformer();
                //setup transformer
                this.transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                this.transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                this.transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text");
                this.transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
            } catch (TransformerConfigurationException tcex) {
                Logger.getLogger(XmlRepository.class.getName()).log(Level.SEVERE, null, tcex);
         * Removes a node by evaluating the XPATH expression.
         * @param xpath A String instance with the XPATH expression representing the element to remove.
         * @throws com.fdt.cognoscere.storage.exceptions.UnableToRemoveException When an exception occurs that prevents the repository to execute the remove statement.
        public void removeNode(final String xpath) throws UnableToRemoveException {
            Node nodeToRemove = null;
            Node parentNode = null;
            //verify xpath
            if (xpath == null)
                throw new IllegalArgumentException("The xpath argument cannot be null.");
            //verify that the repository is loaded
            if (!this.loaded)
                throw new IllegalStateException("The XmlRepository faild to load properly and it is in an invalid state. It cannot perfom any operation.");
            try {
                //get the node to remove out of the xpath expression
                nodeToRemove = this.getNode(xpath);
                //throw an exception if no node was found to remove
                if (nodeToRemove == null)
                    throw new UnableToFindException("The node element trying to be remove does not exist.");
                //obtain the parent node to remove its child
                parentNode = nodeToRemove.getParentNode();
                //remove the node from the parent node
                nodeToRemove = parentNode.removeChild(nodeToRemove);
            } catch.......removed to save space{
            } finally {
                //normalize document
                this.document.normalize();
        }Please tell me if I could do this better,
    thanks,
    f(t)

    franciscodiaztrepat wrote:
    When I remove a node I get a Line Space above the node that was removed, or better put my node gets replaced by a empty line.Replaced? No, there's already a new-line character after the node that was removed. And there was one before that node too. You didn't remove either of those, so after the removal there are two consecutive new-line characters. As you can see.
    And no, trying to pretty-print the XML document won't remove any of those. It might add whitespace to make the document nicely indented, but it won't ever remove whitespace. If you want whitespace removed then you'll have to do it yourself.
    For example, after you remove a node, also remove the node following it if it's a whitespace text node. Or something like that.

  • Xerces 2.6, setIndent(0), 1.4.2 not working. XML always pretty printing

    Hello.
    I would like to take a string that contains xml and strip out all new lines, whitespace between tags, etc. So basically everything will be on one line.
    So I thought one simple way would be to run an XMLSerializer or use a Transformer. However, it's turning out to be a nightmare. I probably could have written a parser already. :)
    I've tried all possible combinations of
    XMLSerializer
    outputFormat.setIndenting(false)
    outputFormat.setIndent(0)
    outputFormat.setLineWidth(0)
    Transformer
    transformer.setOutputProperty("indent", "no")
    transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "0");For some reason, my XML is always pretty printed. And I can't figure it why. I was able to get the XMLSerializer version all on one line with an indent of 1, but the minute I switch to 0 it gets pretty printed.
    Here's some Transformer code I'm using:
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document doc = docBuilder.parse( new InputSource( new StringReader(input)) );                      
    DOMSource source = new DOMSource(doc);
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "no");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "0");
    transformer.transform(source, new StreamResult(System.out));Output:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <trans_data>
      <input_data>
        <cc>1</cc>
      </input_data>
    </trans_data>I've tried both 2.6.2 and 2.5.0 of Xerces and my classpath only has XercesImpl.jar and xml-apis.jar in it. I'm using 1.4.2-07.
    Thanks,
    -- Jason

    public class XMLPrinter
         private static final String CLASSNAME = "XMLPrinter(): ";
         public static String print( String input )
            String methodName = "print(): ";
               String output = "";
            try
                DocumentBuilderFactory docBuilderFactory =
                    DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder =
                    docBuilderFactory.newDocumentBuilder();
                Document doc = docBuilder.parse(
                    new InputSource( new StringReader(input)) );
                StringWriter stringWriter = new StringWriter();
                OutputFormat format = new OutputFormat( doc );
                                                 format.setIndenting( false );
                format.setLineWidth( 0 );
                format.setIndent( 0 );
                XMLSerializer serializer =
                   new XMLSerializer( stringWriter, format );
                serializer.serialize(doc);
                output = stringWriter.toString();
            catch (Exception e)
                output = null;
            return output;
         public static void main(String[] args)
            String XML =
            "<xml> <output>junk</output>    <output2>junk2</output2>\r\n<output3>output3</output3>\r\n</xml>\r\n";
            System.out.println(XMLPrinter.print(XML));
         }returns
    <?xml version="1.0" encoding="UTF-8"?>
    <xml> <output>junk</output>    <output2>junk2</output2> <output3>output3</output3> </xml>Switching to
    format.setLineWidth( 0 );
    format.setIndenting( true );
    format.setIndent( 10 );returns
    <?xml version="1.0" encoding="UTF-8"?>
    <xml>
              <output>junk</output>
              <output2>junk2</output2>
              <output3>output3</output3>
    </xml>

  • Strange Behavior with SQL/XML

    Our University have had for quite some time now a rather difficult situation with a very significant course handbook web site that creates HTML based on database XSL transformation of XML content generated with SQL/XML. The database is 10.2.0.2.0. The HTML is passed via a distributed database link to an Oracle Portal dynamic portlet for display. Some of the derived XML originates from XML Schema registered instance documents and some from relational storage.
    Let me explain. Occasionally after a period of operating (could be one week, sometimes even less) we will experience a problem whereby our derived XML content (just prior to PL/SQL database XSL transformation) will develop a parsing problem. Once this happens to one XSL transform of a course then subsequently it happens for every course viewed/transformed there-after.
    Recently I experienced the problem and then added the XMLNS argument to the extract function. That seemed to fix things and I thought I had it licked.
    Today we started to get the same problem again. The error reported was:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00242: invalid use of ampersand ('&') character (use &amp;)
    Error at line 1
    Now this might have been reasonable for one course. But every course reported the same problem there-after without fail. I managed to fix the issue but in a way that really doesn't seem to make sense. What I did was to alter the SQL/XML statement by adding in an extra XMLEMENT and then to recompile the function that returns an XMLTYPE based on the execution of the SQL statement. After compiling the function everything returned to normal.
    This doesn't seem to make sense.
    I am pretty desperate for help on this. I really don't know how to progress the solution. I don't get much joy from Oracle Support as our application covers too many high tech areas. This is really shaking confidence in our organization's use of Oracle technology.

    Hi Mark.
    We've isolated the problem a bit more now and there is a support SR (6089662.994). At this stage we are unable to reproduce - I am testing out an export though. The problem only occurs when a certain condition has been reached. Once that happens then extraneous characters are produced in the XMLTYPE feed returned by a function. We are not at all sure about how to make this condition occur. This doesn't just happen with one SQL/XML cursor - I've seen it happen with 3 different cursors. All are located in the same function that returns an XMLTYPE.
    We are convinced the problem lies with one or more SQL/XML cursors located in the same function. Once one of these cursors malfunctions it will produce XML that is not well formed OR on occasion has content omitted but is well formed (there often seem to be extraneous characters). When the XML content is not well formed then the parsing stage (dbms_xmlparser.parseclob(myparser, xml_clob)) of XSL transformation crashes. This error then propagates to the dynamic portlet in Oracle Portal thus removing the content on the page. This happens for every execution of the cursor while the condition manifests, the only difference between calls being bind variables.
    The interesting thing is that the error if left to itself will eventually stop. The cursor seems to right itself eventually. On the last occurrence, the problem commenced at 4.30am and went for 3.5 hrs and then seemed to right itself.

  • Xml formatting (pretty print, etc)

    Our MXML is getting a bit messy. (we also need a pretty
    printer and simple
    xml exploration and editing) for soap feeds.
    1. Is there something in Eclipse now that does this?
    2. Is there a publicly available plug-in
    3. Is there some simple (i.e. cheap or free tool) for doing
    this. XMLSpy
    would be overkill.

    Excellent directions, Yes, this is exactly what I needed to
    know. It now
    works fine.
    Only one item to note. Even though I did not set XMLBuddy as
    the default for
    *.mxml
    -- If I do the context menu (right click) and choose xml
    buddy, then it will
    stay sticky for that file the next time. The same as with
    using the
    FlexBuilder mxml editor. Not a real problem but what does
    "default" mean any
    more if the IDE is trying to be so smart as to decide for me
    what my default
    should be :-)
    "Mark Shepherd" <[email protected]> wrote in message
    news:[email protected]...
    > There is no XML or MXML formatting built-in to
    FlexBuilder or Eclipse.
    >
    > But don't despair, there are 100's of plugins available
    for eclipse, here
    > is one way that works...
    >
    > 1. install the XMLBuddy eclipse plug-in from
    xmlbuddy.com
    > 2. in flexbuilder, go to Window > Preferences >
    General > Editors > File
    > Associations
    > 3. select *.mxml in the top panel, then click "Add" in
    the bottom panel
    > 4. choose XMLBuddy, then OK, then OK
    >
    > You can now open any MXML file using the XML editor
    (xmlbuddy) rather than
    > FlexBuilder's normal MXML editor. To do this, select the
    file in the
    > Navigator panel, then right-click and choose Open With
    > XMLBuddy. Once
    > you are in the XML editor, you can select a range of
    text (or the entire
    > file, if you like) and choose Format from the XML menu.
    >
    > This technique will work for any XML-based file format,
    including MXML,
    > soap documents, RSS feeds, etc.
    >
    > There are probably other way to do this. Does anybody
    have other
    > suggestions?
    >
    > Mark Shepherd
    > FlexBuilder Engineering
    >
    >
    > Yechezkal Gutfreund wrote:
    >> Our MXML is getting a bit messy. (we also need a
    pretty printer and
    >> simple xml exploration and editing) for soap feeds.
    >>
    >> 1. Is there something in Eclipse now that does this?
    >>
    >> 2. Is there a publicly available plug-in
    >>
    >> 3. Is there some simple (i.e. cheap or free tool)
    for doing this. XMLSpy
    >> would be overkill.
    >>
    >>

  • PL/SQL + XML with Excel report format?

    Dear all,
    I am a new beginner in XML Publisher. For the EBS11i, I can use PL/SQL with http scripts to generate excel report format.
    The following code will include in store procedure:
    >
    begin
    owa_util.mime_header(ccontent_type => 'application/vnd.ms-excel');
         htp.htmlopen;
         htp.headopen;
         htp.print( '<STYLE>' );
    htp.print( '<!--'||
              '.xl24' ||
              '{mso-style-parent:style0;' ||
                     'mso-number-format:"\@";}' ||
    '.xl41' ||
         '{mso-style-parent:style0;' ||
                   'mso-NUMBER-format:"\#\,\#\#0\.000";}' ||
    '.xl42' ||
         '{mso-style-parent:style0;' ||
                   'mso-NUMBER-format:"\#\,\#\#0\.00";}' ||
    '.xl45' ||
         '{mso-style-parent:style0;' ||
                    'mso-NUMBER-format:"\#\,\#\#0";}' ||
    '-->' );
         htp.print( '</STYLE>' );     
         htp.headclose;
         htp.bodyopen;
         htp.para;
         htp.strong( '<U>' || 'Sample Report Name'|| '</U>');
         htp.para;
    htp.tablerowopen;
         htp.tabledata('<DIV align="left">' || rec_main2.vendor_name || '</DIV>',cattributes => ' class="xl24" width="190"');
    htp.tablerowclose
    >
    How can I do that in R12?
    Please advice.

    We currently do not support SQL aliasing of directories. This
    is causing your errors.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    Frank Hubeny (guest) wrote:
    : I think I got past this point by first creating a directory
    : under sys and then granting read privileges to owner of the
    : domsample procedure (in my case the this user is called "xml").
    : create directory xml as 'e:\web\xml';
    : grant read on directory xml to xml;
    : Then the call becomes (I think)
    : exec domsample ('XML','family.xml','test.err')
    : However, I am getting the following error:
    : ERROR at line 1:
    : ORA-20100: Error occurred while parsing: XML/err.log
    : ORA-06512: at "XML.XMLPARSER", line 43
    : ORA-06512: at "XML.XMLPARSER", line 120
    : ORA-06512: at "XML.DOMSAMPLE", line 80
    : ORA-06512: at line 1
    : The readme says "It is necessary for the user running
    : this sample to have been granted the appropriate security
    : priveleges to read and write from a file on the file
    : system." I am not sure what the "write" grant would be.
    : And so I also set utl_file_dir so that it pointed to
    : the directory. But somehow I don't think that utl_file is
    : needed in this context. In any case, it appears I cannot write
    : to the err.log file or find it.
    : Brad Douglass (guest) wrote:
    : : I'm receiving the following error when I use the domsample
    : : procedure supplied with the PL/SQL XML parser:
    : : SQL> exec domsample('e:\web\xml','test.xml','test.err');
    : : begin domsample('e:\web\xml','test.xml','test.err'); end;
    : : ERROR at line 1:
    : : ORA-20101: Error occurred while accessing a file or URL:
    : unknown
    : : protocol: file
    : : ORA-06512: at "XML.XMLPARSER", line 46
    : : ORA-06512: at "XML.XMLPARSER", line 164
    : : ORA-06512: at "XML.DOMSAMPLE", line 77
    : : ORA-06512: at line 1
    : : UTL_FILE doesn't have any problems with the file.
    : : Any ideas?
    null

  • Validate xml with PL/SQL Parser

    Hi,
    i have an xml DTD into a VARCHAR2 variable and an xml document
    into a CLOB, i'd like to know how to validate the xml with my
    DTD using PL/SQL API for xml.
    Sorry for my terrible english (i'm not english) :-)
    Tank you.

    Here's an example:
    set serveroutput on
    DECLARE
      p xmlparser.parser;
      d xmldom.DOMDocument;
      dtd xmldom.DOMDocumentType;
      v varchar2(32700);
      good clob;
      bad clob;
      xml_parse_error exception;
      pragma exception_init(xml_parse_error,-20100);
    BEGIN
      bad   := '<!DOCTYPE Department SYSTEM "test.dtd"><Deprtment/>';
      good  := '<!DOCTYPE Department
    SYSTEM "test.dtd"><Department/>';
      v := '<!ELEMENT Department EMPTY>';
      p := xmlparser.newParser;
      xmlparser.parseDTDBuffer(p,v,'Department');
      xmlparser.setDoctype(p,xmlparser.getDoctype(p));
      xmlparser.setValidationMode(p,TRUE);
      xmlparser.parseClob(p,good);
      xmlparser.parseClob(p,bad);
      xmlparser.freeParser (p);
    EXCEPTION
      WHEN xml_parse_error THEN
         DBMS_OUTPUT.PUT_LINE(sqlerrm);
         xmlparser.freeParser (p);
    END;

Maybe you are looking for

  • IP: query shows only open request data, when filtered

    Hi, I can see only data of the open request. but it depends on the filter. I have a real-time provider with closed requests and one open request. (The closed requests come from manually switching between planning and loading mode.) On top there is a

  • To check the source code(VI) in absence of real hardware

    I need to check the VI , which is developed to measure pressure with pressure transducer. Later this VI is deplyed in the Test stand system as .exe file. At the test stand system we have all the hardware from the PCI DAq card to the pressure transduc

  • HT201250 Is Time Machine Scalable?

    I have a MBA with about 150GB of files and a TIme Capsule.  It looks like this is too much for Time Machine to handle.  The initial backup takes 2 days and the hourly backups take more than an hour.  While the backup processes are running my MBA occa

  • Film to Digital Video, a good method?

    I'm considering buying a Film camera, possibly a used Arriflex Super 16, rather than spending alot more on a comparable HD camera. My only dillemma is transfering the film to digital. I read on a different forum that you can get decent transfer quali

  • Redemption code will not work for serial number

    Put my code in and it says it's not been activated.