Sorting XML using DOM4J

Hi All,
Below is a sample XML which needs to be sorted based on the "id" attribute of the "key" element.
<?xml version='1.0'?>
<main>
<key id='16066'>
<key id='16061'>
<key id='11'>
<key id='1'>
<key id='2'>
<key id='1001'>
</main>
I am trying to sort the XML using the below function using DOM4J
List xmlList = document.selectNodes("//main/key","@id")
But the List is not sorted based on the number.
I found that this does not happen even through XSLT because
When sorting in default mode, the sorting is performed using alphabetic string comparisons. If numbers are to be sorted according to their numeric value, data-type must be set to "number".
for example : "<xsl:sort data-type="number"/>"
But, how do we do this using DOM4J.
Please advice how to sort the numbers in an XML without using XSLT
Thanks in advance,
Raju

Write your own code that manipulates the DOM.

Similar Messages

  • Query on sorting  XML using XSLT and getting the same XML as output !

    Hi,
    Looking for one information regarding sorting XML using XSLT , with the sorted XML as output. For eg. my XML is :
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="sort1.xsl"?>
    <levelone>
         <child ID="1" sort="5">
              <name>Paul</name>
         </child>
         <child ID="2" sort="1">
              <name>Adam</name>
         </child>
         <child ID="3" sort="2">
              <name>Will</name>
         </child>
    </levelone>
    and XSL :
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/levelone">
         <xsl:copy>
         <xsl:apply-templates>
              <xsl:sort select="@sort"/>
         </xsl:apply-templates>
              </xsl:copy>
         </xsl:template>
         <xsl:template match="child">
              <xsl:copy-of select="."/>
         </xsl:template>
    </xsl:stylesheet>
    This does the sort based on Name. But I want to get the same xml as output with the name sorted. Eg.
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="sort1.xsl"?>
    <levelone>
         <child ID="2" sort="1">
              <name>Adam</name>
         </child>
         <child ID="1" sort="5">
              <name>Paul</name>
         </child>
         <child ID="3" sort="2">
              <name>Will</name>
         </child>
    </levelone>
    Any pointers will be highly appreciated.
    - Thanks

    Don't you want <xsl:sort select="name"/> rather than <xsl:sort select="@sort"/>?

  • Xml parsing using dom4j

    I have some XML in String format, and I want to use the DocumentHelper.parseText() method on that string to parse it to Document format.
    I use it and it doesn't say anything about an error, however when I try to get "getelementroot()" and "getattributevalue" it gives me null.
    The XML looks like this:
    <Response status="1">
    <ERROR code="1">Offer is not available. </ERROR>
    <OFFER_ID>fPSC00010_PKG</OFFER_ID>
    </Response>
    I want to get the value of "status", i.e 1 in this case. So I do something like this:
    Element e = doc.getRootElement();
    String s = e.attributeValue("Status");
    Have I misunderstood something or what?

    Well I am not 100% sure why your code is causing a problem. I used dom4j 1 year ago.
    But I can give you my code snippet, the difference there to your snippet is that I first retrieved an Iterator over the Root element. And as I think the root element in your case is not the "Response" element it is more like a pointer to the start of the document. I am sorry for my vague explanation,it's too long age.
    But I am sure that you can use my example for your need effectively.
    public XMLMetaReader( String fileName )
            Document document = null;
            try
                SAXReader reader = new SAXReader( true );
                document = reader.read( fileName );
                root = document.getRootElement();
                createDBTree();
            catch ( DocumentException e )
                e.printStackTrace();
        public Map getSourceTables()
            return sourceTables;
        /** Return all tables which are set in the currently connected Database. */
        private void createDBTree() throws DocumentException
            for ( Iterator iterator0 = root.elementIterator( "database" ); iterator0.hasNext(); )
                Element databaseNode = ( Element ) iterator0.next();
                database = databaseNode.attributeValue( "ID" );
                // iterate through child elements of root with element name "table"
                for ( Iterator iterator = databaseNode.elementIterator( "table" ); iterator.hasNext(); )
                    Element tableNode = ( Element ) iterator.next();
                    Table table = new Table( tableNode.attributeValue( "ID" ) );
                    sourceTables.put( tableNode.attributeValue( "ID" ), table );
                    // iterate through child elements of root with element name "field"
                    for ( Iterator iterator2 = tableNode.elementIterator( "field" ); iterator2.hasNext(); )
                        Element fieldNode = ( Element ) iterator2.next();
                        Field field = new Field( fieldNode.attributeValue( "ID" ) );
                        field.setOriginalDomain( fieldNode.attributeValue( "datatype" ) );
                        if ( fieldNode.attributeValue( "default" ) != null )
                            String fieldValue = fieldNode.attributeValue( "default" );
                            if ( ( fieldValue ).equalsIgnoreCase( "NULL" ) )
                                field.setIsOriginalNullable( true );
                            else if ( ( fieldValue ).equalsIgnoreCase( "NOT NULL" ) )
                                field.setIsOriginalNullable( false );
                            else
                                field.setOriginalDefault( fieldValue );
                        table.addField( field );
                    for ( Iterator iterator2 = tableNode.elementIterator( "primarykey" ); iterator2.hasNext(); )
                        Element primaryNode = ( Element ) iterator2.next();
                        for ( Iterator iterator3 = primaryNode.elementIterator( "key" ); iterator3.hasNext(); )
                            Element keyNode = ( Element ) iterator3.next();
                            table.addPrimaryKey( keyNode.attributeValue( "field" ) );
                            Field primaryField = table.getField( keyNode.attributeValue( "field" ) );
                            primaryField.setIsOriginalPrimary( true );
                    for ( Iterator iterator2 = tableNode.elementIterator( "foreignkey" ); iterator2.hasNext(); )
                        Element foreignNode = ( Element ) iterator2.next();
                        ForeignKey foreignKey = new ForeignKey();
                        for ( Iterator iterator3 = foreignNode.elementIterator( "key" ); iterator3.hasNext(); )
                            Element keyNode = ( Element ) iterator3.next();
                            foreignKey.setOnField( keyNode.attributeValue( "field" ) );
                            System.out.println( keyNode.attributeValue( "field" ) );
                            foreignKey.setReferencedTable( keyNode.attributeValue( "references" ) );
                            System.out.println( keyNode.attributeValue( "references" ) );
                        for ( Iterator iterator3 = foreignNode.elementIterator( "onupdate" ); iterator3.hasNext(); )
                            Element onUpdateNode = ( Element ) iterator3.next();
                            foreignKey.setOnUpdate( onUpdateNode.attributeValue( "action" ) );
                        for ( Iterator iterator3 = foreignNode.elementIterator( "ondelete" ); iterator3.hasNext(); )
                            Element onDeleteNode = ( Element ) iterator3.next();
                            foreignKey.setOnDelete( onDeleteNode.attributeValue( "action" ) );
                        table.addForeignKey( foreignKey );
                    for ( Iterator iterator2 = tableNode.elementIterator( "index" ); iterator2.hasNext(); )
                        Element indexNode = ( Element ) iterator2.next();
                        Index index = new Index( indexNode.attributeValue( "name" ) );
                        index.setIsUNIQUE( ( indexNode.attributeValue( "unique" ) ).equalsIgnoreCase( "true" )  );
                        index.setIsDESC( ( indexNode.attributeValue( "ASC" ) ).equalsIgnoreCase( "true" )  );
                        /* index.setTable( tableNode.attributeValue( "ID" ) ); */
                        for ( Iterator iterator3 = indexNode.elementIterator( "indexfield" ); iterator3.hasNext(); )
                            Element indexFieldElement = ( Element )iterator3.next();
                            int position = Integer.parseInt( indexFieldElement.attributeValue( "position" ) );
                            index.addField( indexFieldElement.attributeValue( "field" ), ( short ) position );
                        table.addIndex( index );
                    for ( Iterator iterator2 = tableNode.elementIterator( "uniqueclause" ); iterator2.hasNext(); )
                        Element uniqueNode = ( Element ) iterator2.next();
                        UniqueConstraint uniqueConstraint = new UniqueConstraint();
                        for ( Iterator iterator3 = tableNode.elementIterator( "uniquefield" ); iterator3.hasNext(); )
                            Element uniqueFieldNode = ( Element ) iterator3.next();
                            uniqueConstraint.addField( uniqueFieldNode.attributeValue( "field" ) );
    }Hope it helps.
    Best regards
    Tarik

  • XML to Excel file using dom4j

    hi!
    i'm new with dom4j and i don't have any idea on how to do the following task:
    i have an xml document which i have to save as an excel file using dom4j. my problem is i also have to insert records in the middle of the file. is it possible?
    sample layout:
    Worksheet Header (also have to plot a value)
    Column Header (also have to plot a value)
    -- need to insert records here --
    Sub-total row
    Total row
    i would appreciate any help from you guys...
    thanks in advance...

    Hi there!
    First I haven't seen any application that uses dom4j to write excel's file, but I can recommend you to use Apache's POI to write and read from any excel's file, actually I'm working rigth now with it, and works fine with Office 2003.
    http://jakarta.apache.org/poi/hssf/
    For the XML you can use what ever you feel confortable with, dom4j, jdom, etc. I really like jdom thougth

  • Parsing xml with dom4j - cannot find jar file

    Hi,
    I'm using Jdeveloper 10g and tomcat 5.5.9. I have a servlet which calls a java class (ParseXML.java) that trys to parse an xml string using dom4j. A snippet of ParseXML.java...
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    public class ParseXML  {
    public ParseXML(String xml) {
              this.XML_STRING = xml;
         public String parse() {
              SAXReader reader = new SAXReader();
              Document document = null;
              try  {
                   document = reader.read(XML_STRING);
                   } catch (DocumentException de)  {
                   return de.getMessage();
              } catch (Exception e) {
                   return e.getMessage();
                   return "The xml root value is: " + document.getRootElement().getName();
    } I've downloaded the dom4j 1.6.1 jar and put it on the project class path (specified in the jdev project proerties), and my code also compiles ok. But when i try to instantiate ParseXML from my servlet i get a runtime exception:
    javax.servlet.ServletException: Servlet execution threw an exception
    root cause
    java.lang.NoClassDefFoundError: org/dom4j/DocumentException
         arcims.GetMapServlet.doPost(GetMap.java:45)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802I'm not sure if this is a class path issue or something else; i've checked and rechecked the classpath and nothing seems amiss.
    Suggestions, anyone?

    Question: Is it really necessary to use a
    StringReader if my xml document is not saved to disk?
    I get XML_STRING from a web service, convert it into
    a xml document so i can manipulate/parse it, but then
    i don't save the document, i just discard it. How
    does my system's default character set affect string
    manipulations that i do within my java app?Your system's default charset doesn't have anything to do with string manipulations, if by that you mean substrings and concatenations of strings. It is used when you convert strings to bytes and bytes to strings. If your string contains a character that can't be handled by your default charset, then converting that string to bytes will put ? in place of that character. Converting those bytes back to a string will leave the ? as is. Thus your string has been changed.
    Also converting the string to bytes can have bad results, because the first thing the XML parser does is to convert the bytes back to a string, using the charset declared in the XML. If this charset is different from your system's default, then your XML may be corrupted by this process if it contains characters that are encoded differently in the two charsets. The typical example of this is European accented letters like �, which are encoded differently in ISO-8859-1 or Windows-1252 (most people's default charsets) and UTF-8 (the default XML charset).
    Besides, converting the string to bytes just so it can be immediately converted back to a string is rather wasteful.

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • Maximum file handled using dom4j

    Hi,
    Wanna know whats the maximum xml file size that can be handled using dom4j.
    To be precise, I have a 1gb xml file that I wanna parse, I have implemented it using SAX, but wanna know if dom4j can be used?
    Regards,
    R

    Just try, you'll probably only be limited by available memory. I assume that building any kind of DOM tree of the document (be it org.w3c.dom or dom4j) will use more memory than the original file. So you'll need > 1 GB of memory for your file. If you have to handle files that big and don't absolutely need it all at the same time then SAX is probably the better solution as it doesn't require the whole file to be in memory at a time.

  • Can I 'sort' XML in Flash

    Hello,
    Is it possible to sort XML in any way in Flash?
    For example in MYSQL I can SELECT a column and ORDER BY...
    In Flash I need to SELECT an XML child object and sort all
    parent items
    accordingly.
    Thanks,
    David

    It would be great if there was a way in Flash 8 to sort XML
    based on a
    certain element without duplicating work making an array?
    See a simple XML example below:
    <?xml version='1.0' encoding='utf-8'?>
    <data>
    <item>
    <title>Apple</title>
    <price>7</ price>
    </item>
    <item>
    <title>Carrot</title>
    <price>2</ price>
    </item>
    <item>
    <title>Banana</title>
    <price>6</ price>
    </item>
    </data>
    If I could sort this by cheapest price, this would give
    results -
    1. Carrot
    2. Banana
    3. Apple
    Or by Alphabetical order:
    1. Apple
    2. Banana
    3. Carrot
    Any suggestions - is this possible with the Flash XML object?
    On 15/2/07 16:41, in article
    er22gb$rpp$[email protected], "albee"
    <[email protected]> wrote:
    > Why not organize the XML data into an Array, and then
    use Array.sort() or
    > Array.sortOn()?
    >
    > Albee

  • Error while using dom4j

    Hi
    I am using dom4j for generating xml file ,but when I am trying to run a batch(which invokes java file(uses dom4j)), it is giving me error as --> Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/Branch
    I have set the jar file in the CLASSPATH and also put it in the server(weblogic) lib directory.Still I am getting the same problem.
    Server is weblogic and OS is windows.
    Please help
    Thanks
    Piyush

    What's a "batch"? You were talking about the classpath, then you switched to talking about Weblogic. It's not clear what is your context nor what you are trying to do.

  • Using DOM4J XPath

    IM going nuts trying to use DOM4J to query something so simple. Here is the input XML file and the code to run the XPath. If I loop through the document using the annoying element and node map thing it works fine and I can get all the nodes. But I want to run an XPath query right to the information I want. Firs time I tried without the URI nodes and this time I tried it with it. Still no luck.
    XML FILE
    <?xml version="1.0"?>
    <configs>
         <config SERVICE="Service Name">
              <detail name="key">value</detail>
         </config>
         <config SERVICE="ProcessErrors">
              <detail name="ErrorEmailAddresses">[email protected]</detail>
         </config>
         <config SERVICE="TestSQLErrors">
              <detail name="ErrorEmailAddresses">[email protected]</detail>
         </config>     
    </configs>CODE
    File fXmlFile = new File("n:\\config.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();
    XPath xpathNodes = new DefaultXPath("//configs/config[@SERVICE='ProcessErrors']/detail[@name='ErrorEmailAddresses']");
    HashMap<String, String> mapNodes = new HashMap<String,String>();
    xpathNodes.setNamespaceURIs(mapNodes);          
    Node exceptionNode = (Node)xpathNodes.selectSingleNode(doc);
    System.out.println(exceptionNode);exceptionNode is empty. If I run this same query on the same document in XML spy I get the value.???

    For obscure products it's generally better to ask on the forum or mailing list associated with that product. You're more likely to encounter people who have heard of the product and actually know something about it.
    On the other hand if it doesn't have a forum or mailing list, or there's no activity on that forum or mailing list, that's a hint you should consider using something more commonly used.

  • Sorting xml

    hi,
    How can I sorting xml file before parsing it.
    for example:
    parser.parse("test.xml");
    Document doc = parser.getDocument();
    Thanks.

    you can sort the data using xsl. Here's what i'm doing
    empdata.xml file
    ========
    <?xml version="1.0"?>
    <?xml-stylesheet href="empdata.xsl" type="text/xsl"?>
    <employees>
    <employee>
    <name>
         <got>4</got>
    <given>James</given>
    <family>Cook</family>
    </name>
    </employee>
    <employee>
         <name>
         <got>5</got>
    <given>Aames</given>
    <family>Dlark</family>
    </name>
    </employee>
    <employee>
         <name>
         <got>1</got>
         <given>Bames</given>
    <family>Dlark</family>
    </name>
    </employee>
    <employee>
    <name>
         <got>3</got>
         <given>marshesi</given>
    <family>park</family>
    </name>
    </employee>
    <employee>
    <name>
         <got>7</got>
    <given>Lames</given>
    <family>lamb</family>
    </name>
    </employee>
    </employees>
    empdata.xsl
    ===========
    <?xml version="1.0"?>
    <xsl:stylesheet version='1.0'     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
    <xsl:output method="xml" indent='yes'/>
    <xsl:template match="employees">
    <ul>
    <xsl:apply-templates select="employee">
    <xsl:sort select="name/got"/>
    <xsl:sort select="name/family"/>
    <xsl:sort select="name/given"/>
    </xsl:apply-templates>
    </ul>
    </xsl:template>
    <xsl:template match="employee">
    <li>
    <xsl:value-of select="name/got"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="name/given"/>
    <xsl:text> </xsl:text>
    <xsl:value-of select="name/family"/>
    </li>
    </xsl:template>
    </xsl:stylesheet>
    I hope this will help you.
    sachin

  • How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?

    How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
    Hi,
    I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
    but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
    ( f.ex. cannot verifying it correct in xmlspy )
    my dbms is
    NLS_CHARACTERSET          = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET     = AL16UTF16
    NLS_RDBMS_VERSION     = 10.2.0.1.0
    I do generate it in this matter :
    declare
    xmldoc CLOB;
    ctx number ;
    utl_file.file_type;
    begin
    -- generate fom xml-view :
    ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
    DBMS_XMLGEN.setRowSetTag(ctx, null);
    DBMS_XMLGEN.setRowTag(ctx, null );
    DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
    -- create xml-file:
    xmldoc := DBMS_XMLGEN.getXML(ctx);
    -- put data to host-file:
    vblob_len := DBMS_LOB.getlength(xmldoc);
    DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
    bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
    UTL_FILE.put_line(bHandle, vbuffer, FALSE);
    UTL_FILE.fclose(bHandle);
    end ;
    maybe while work UTL_FILE there is a change the encoding ?
    How can this solved ?
    Thank you
    Norbert
    Edited by: astramare on Feb 11, 2009 12:39 PM with database charsets

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • String to XML using XSLT..

    Hey folks
    Am having a XML in a single string in ma request and wanna convert that into a XML. Tried that using XSLT but seems am missing out on some point...It works fine with Stylus but fails within PI 
    Following code am using :
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://www.sdn.com/xslt">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
       <xsl:template match="/">
            <xsl:for-each select="//*:string">
             <xsl:value-of select="." disable-output-escaping="yes"/>
          </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    The name of the element in which i get the whole XML is  "string".
    My request string is something liek this :
    <xml version="1.0" encoding="UTF-8"?><ProductDefinition><RefNo>23232323</RefNo><Description>dfdfdfdfdf</Description></ProductDefinition>
    Now am trying to generate a XML using the XSL but its failing in PI...
    Kindly point out where am i going wrong?

    Thanks, but graphical mapping does not expose <![CDATAhttp:// ... ] to be removed. Surely this must be done with XSLT?+
    Don't worry about <![CDATA ... pass your whole string in source message like this : <![CDATAhttp://<?xml version=\"1.0\" encoding=\"UTF-8\"?><ProductDefinition><RefNo>12345</RefNo><Description>Test</Description></ProductDefinition>]>
    1st the graphical mapping where you use replace string will replace <?xml version=\"1.0\" encoding=\"UTF-8\"?>  and then the XSLT mapping would get a input like this : <![CDATAhttp://<ProductDefinition><RefNo>12345</RefNo><Description>Test</Description></ProductDefinition>]> which would eventually form your target structure...
    I tried it myself few days back so its a sure shot method ... just try it 
    Cheers!!!
    Soumen 

  • Problem in parsing an XML using SAX parser

    Hai All,
    I have got a problem in parsing an XML using SAX parser.
    I have an XML (sample below) which need to be parsed
    <line-items>
    <item num="1">
         <part-number>PN1234</part-number>
         <quantity uom="ea">10</quantity>
         <lpn>LPN1060</lpn>
         <reference num="1">Line ref 1</reference>
         <reference num="2">Line ref 2</reference>
         <reference num="3">Line ref 3</reference>
    </item>
    <item num="2">
         <part-number>PN1527</part-number>
         <quantity uom="lbs">5</quantity>
         <lpn>LPN2152</lpn>
         <reference num="1">Line ref 1</reference>
         <reference num="2">Line ref 2</reference>
         <reference num="3">Line ref 3</reference>
    </item>
    <item num="n">
    </item>
    </line-items>
    There can be any number of items( 1 to n). I need to parse these
    item values using SAX parser and invoke a stored procedure for
    each item with its
    values(partnumber,qty,lpn,refnum1,refnum2,refnum3).
    Suppose if there are 100 items, i need to invoke the stored
    procedure sp1() 100 times for each item.
    I need to invoke the stored procedure in endDocument() method of
    SAX event handler and not in endelement() method.
    What is the best way to store those values and invoke the stored
    procedure in enddocument() method.
    Any help would br greatly appreciated.
    Thanks in advance
    Pooja.

    VO or ValueObject is a trendy new name for Beans.
    So just create an item class with variables for each of the sub elements.
    <item>
    <part-number>PN1234</part-number>
    <quantity uom="ea">10</quantity>
    <lpn>LPN1060</lpn>
    <reference num="1">Line ref 1</reference>
    <reference num="2">Line ref 2</reference>
    <reference num="3">Line ref 3</reference>
    </item>
    public class ItemVO
    String partNumber;
    int quantity;
    String quantityType;
    String lpn;
    List references = new ArrayList();
    * @return Returns the lpn.
    public String getLpn()
    return this.lpn;
    * @param lpn The lpn to set.
    public void setLpn(String lpn)
    this.lpn = lpn;
    * @return Returns the partNumber.
    public String getPartNumber()
    return this.partNumber;
    * @param partNumber The partNumber to set.
    public void setPartNumber(String partNumber)
    this.partNumber = partNumber;
    * @return Returns the quantity.
    public int getQuantity()
    return this.quantity;
    * @param quantity The quantity to set.
    public void setQuantity(int quantity)
    this.quantity = quantity;
    * @return Returns the quantityType.
    public String getQuantityType()
    return this.quantityType;
    * @param quantityType The quantityType to set.
    public void setQuantityType(String quantityType)
    this.quantityType = quantityType;
    * @return Returns the references.
    public List getReferences()
    return this.references;
    * @param references The references to set.
    public void setReferences(List references)
    this.references = references;

  • Error in Parsing XML using fx:XML/ [Error- 1090: XML parser failure: element is malformed]

    Hi All,
    I am getting error while loading XML in <fx:XML> tag.
    Error:
    TypeError: Error #1090: XML parser failure: element is malformed.
    MXML Code:
    <fx:Declarations>
    <fx:XML id="xmlSource2" source="sample.xml"/>
    </fx:Declarations>
    Sample XML Used: (sample.xml)
    <?xml version="1.0" encoding="UTF-8"?>
    <File>
        <Chemical id="000035676" displayFormula="C39-H45-N2-O6"
            displayName="Dimethyltubocurarine">
            <NameList>
                <NameOfSubstance>
                    Dimethyltubocurarine
                    <SourceList>
                        <Source>MESH</Source>
                    </SourceList>
                </NameOfSubstance>
                <SystematicName>
                    Tubocuraranium, 6,6',7',12'-tetramethoxy-2,2',2'-trimethyl-
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </SystematicName>
                <Synonyms>
                    Dimethyltubocurarine
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </Synonyms>
                <Synonyms>
                    Dimethyltubocurarinium
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </Synonyms>
                <Synonyms>
                    Methyltubocurarinum
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </Synonyms>
            </NameList>
            <NumberList>
                <CASRegistryNumber>
                    35-67-6
                    <SourceList></SourceList>
                </CASRegistryNumber>
                <RelatedRegistryNumber>
                    518-26-3 (iodide.hydriodide)
                    <SourceList>
                        <Source>MESH</Source>
                    </SourceList>
                </RelatedRegistryNumber>
            </NumberList>
            <ClassificationList>
                <ClassificationCode>
                    Neuromuscular nondepolarizing agents
                    <SourceList>
                        <Source>MESH</Source>
                    </SourceList>
                </ClassificationCode>
            </ClassificationList>
            <FormulaList>
                <MolecularFormula>
                    C39-H45-N2-O6
                    <SourceList>
                        <Source>NLM</Source>
                    </SourceList>
                </MolecularFormula>
            </FormulaList>
            <FormulaFragmentList></FormulaFragmentList>
            <NoteList></NoteList>
            <LocatorList>
                <FileLocator
                    url="http://cnetdb.nci.nih.gov/cgi-bin/srchcgi.exe?DBID=****3&SFMT=****_basic%2F10%2F0%2F0&TYPE=search&SRCHFORM=passthru%3D%Asrchform%3ASRCH%3A&FIELD_001=[CAS]35-67-6&#38;GoButton=Search&#38;FIELD_001_CTL=EXPR&#38;FIELD_908=&#38;FIELD908_CTL=HASABSTRACT&#38;FIELD_903=&#38;FIELD_903_CTL=YEARFORE&#38;DOCPAGE=10">CANCERLIT</FileLocator>
                <FileLocator
                    url="http://toxnet.nlm.nih.gov/cgi-bin/sis/search/r?dbs+toxline:@and+@term+@rn+35-67-6+@term+@org+DART">DART/ETIC</FileLocator>
                <FileLocator
                    url="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=search&db=PubMed&term=35-67-6[ECNO]+OR+&#34;~&#34;[MH]">MEDLINE</FileLocator>
                <FileLocator
                    url="http://www.nlm.nih.gov/cgi/mesh/2K/MB_cgi?term=35-67-6&rn=1">MESH</FileLocator>
                <FileLocator
                    url="http://toxnet.nlm.nih.gov/cgi-bin/sis/search/r?dbs+toxline:@term+@rn+35-67-6+@OR+@mh+""">TOXLINE</FileLocator>
            </LocatorList>
        </Chemical>
    </File>
    Also, when I am using HttpService to load same XML I am getting no such error!!
    <s:HTTPService id="employeeService"
                           url="sample.xml"
                           result="employeeService_resultHandler(event)"
                           fault="employeeService_faultHandler(event)"/>
    Please help!!
    Thanks.
    Abhinav

    I think url in XML is creating problem here.
    <FileLocator
                    url="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=search&db=PubMed&term=23-95-0[ECNO]+OR+&#34;~&#34;[MH]">MEDLINE</FileLocator>
    Is there any way to parse this XML using <fx:XML/> ??
    Thanks.

Maybe you are looking for

  • How do I find a copy of installer image of 10.7.5?

    I want to create a emergency Bootable USB drive for recovery procedure. My system can't be upgraded above 10.7.5 since it is 32 bit system (Mac Pro) so I can't just upgrade the OS. I've searched for .dmg files on my system but I must have deleted it.

  • Bug in iPod.app on iPhone?

    Since updating to 3.0, some of my MP3 files, like "What if" from Coldplay's X&Y, start playing at around 60% of the total track time when i click begin. "What if" and "White Shadows" start at exactly 3:17 and 3:19, respectively. But the rest of the a

  • Does your iphone 5 white leak light?

    Ok so I was reading some posts that says that the iPhone 5 white leaks light on the right had side by the power button so I went to a dark room to see if mine did this to and low and behold it does, I'm so very disappointed and ****** off, I'm afraid

  • Re positioning of a  JS menu (has links)

    HI, I have a link to the page I'm wotking on http://www.oldfields.com.au/access/index.htm the grey menu on the left side doesn't fit in. It is a java script menu that is linked to other pages, so it is seen on all the pages in the "access" section. O

  • How to open Outlook, generate an email with Web Dynpro ABAP

    Hi Experts, I have to generate an email which must be open with MS Outlook. The body will be filled by values from the IView, then Outlook should be open and the email should be shown so that the user can change or add s.th. in the email. I tried it