XML Parsing with XSL Performance lag

Hi there
I should qualify this post by saying I am fairly new to EJB's and have based the below on a Java Working with XML Tutorial I read.
I have an EJB which is being developed to parse XML documents with an XSL stylesheet and return HTML for display. The code is working fine however there is a fairly hefty performance lag when using the EJB to generate the HTML as opposed to the straight HTML. I am getting an average response time of 95000ms using the EJB as opposed to 45000ms when viewing the straight HTML. The code I am using to do the parsing is :
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(dataFile);
// Convert docs into StreamSource
StreamSource stylesource = new StreamSource(styleSheet);
StreamSource source = new StreamSource(dataFile);
StringWriter strWrite = new StringWriter();
StreamResult result = new StreamResult(strWrite);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(stylesource);
transformer.transform(source, result);
There is then some error handling and the strWrite object is placed into an array to be returned.
I am really looking to find out if the performance lag I am experiencing is normal or if there is anything I can do to improve the speed of the code.
All comments and help is most appreciated.
Cheers
Justin.

You should be able to increase performance by caching Templates objects in memory as a previous post suggested.
Here is some untested code:public final class TransformerCache
     private static Map cache = new Vector();
     private TransformerCache(){}
     public static Transformer getTransformer( String filename )
          if( ! cache.containsKey( filename ) )
               TransformerFactory tf = TransformerFactory.newInstance();
               Templates template = tf.newTemplates( new StreamSource( filename ) );
               cache.put( filename, template );     
          return ( ( Templates ) cache.get( filename ) ).newTransformer();
}This aproach works in a clustered environment, just bear in ming that there will be an instance of the cache on each server instance (virtual machine).

Similar Messages

  • Transfer 100M XML file with XSL

    Hi,
    I am trying to transfer 100M XML file with XSL. Input.xml is the XML file, format.xsl is the XSL file. I type in the command line as:
    java org.apache.xalan.xslt.Process -IN input.xml -XSL format.xsl -OUT output.xml
    It got "out of memeory" error. My questions are:
    1. Is it possible to transfer such large XML file with XSLT?
    2. The XSL processor used SAX or DOM to parse XML file?
    3. Any suggestions?
    Thanks.
    James

    maybe?
    java -Xmx200m org.apache.xalan.xslt.Process -IN input.xml -XSL format.xsl -OUT output.xml
    http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java-classic.html

  • Which XML Parser gives best performance? Please respond!!

    Hi,
    I am trying to figure out what is the best performing XML parser. I know that SAX implementation is good for XML reading and DOM is good when building XML documents.
    Now, I want to know which parser (JAXP? JDOM? Piccolo?) I understand that JAXP underneath uses Xerces and SAX2. Is it right?
    Is it a good practice to have a single application using a SAX parser for reading xml docs and a DOM parser to build xml parser?
    We are also planning to migrate from Apache Soap to Apache Axis. Do you have any recommendations?

    I think JAXP is an API, not a parser. It uses an underlying parser called Crimson by default. If you want it to use other parsers you can configure it to do so. I can't tell you which parser is more fastest.
    The easiest way of reading and writing XML documents is to use an XML data binding library such as JAXB or castor. It's much nicer than implementing the SAX callback methods or building document trees. The steps involve are...
    1. Write an XML Schema
    2. Tell the XML data binding tool to generate the source code to marshall / unmarshall XML documents to and from java objects
    3. Compile the source code
    4. Package the classes into a library
    5. Use the library in your application
    Steps 2-4 can be added into your build script.
    It may take you a couple of days to become familiar with the tools, but will save you weeks of maintenance & debugging.

  • XML parser with document support

    Hi all,
    For a whole week now, I m still looking for a nice (but lite) XML parser for J2ME applications. Of course I found kXML 2 parser but I'm confused.
    kXML 2 implements the XmlPull API (xmlpull.org) so you can parse easly an XML file with functions as next(), ...
    BUT, I would like to deal with a Document Object Model (DOM) (like JDom for J2SE), with this I will be able to do some nice stuff like doc.getRoot().getElement....
    In kXML2 Javadoc I found something like this but apparently it doesnt work well (or I dont know how to use it).
    Do someone know this API ? http://kxml.sourceforge.net/kxml2/javadoc/
    I can't find any example on Internet, everybody seems to use it without DOM....
    Until someone give me an answer I will continue to use kXML2 without document object model :(
    thanks guys,

    just a search..in http://sourceforge.net/
    http://sourceforge.net/search/?type_of_search=soft&type_of_search=soft&words=dom+j2me

  • XML parsing with SQL/PL-SQL

    Hi,
    My question is about how can an XML message can be best parsed using SQL/PL-SQL.
    The scenario is as follow. The XML message is stored in a CLOB; only some of its data needs to be extracted; there are six different types of structures of XML; the size of each XML is about 50 lines (maximum depth level is 3); the data could be written in English or Greek or French or German or Russian; this is going to be done every hour and the parsing is going to be against 3,000 records approx.
    In the development, I need to take into consideration performance. We are using Oracle 10, but we could migrate to Oracle 11 if necessary.
    Apologies for this basic question but I have never done XML parsing in SQL/PL-SQL before.
    Thank you.
    PS I have copied this question to the XML forum.
    Edited by: user3112983 on May 19, 2010 3:30 PM
    Edited by: user3112983 on May 19, 2010 3:39 PM

    user3112983 wrote:
    The scenario is as follow. The XML message is stored in a CLOB; only some of its data needs to be extracted; there are six different types of structures of XML; the size of each XML is about 50 lines (maximum depth level is 3); the data could be written in English or Greek or French or German or Russian; this is going to be done every hour and the parsing is going to be against 3,000 records approx.Parsing is done using the XMLTYPE data type (object class) in Oracle.
    Something as follows:
    SQL> create table xml_doc( id number, doc clob );
    Table created.
    SQL>
    SQL> insert into xml_doc values( 1, '<root><row><name>John</name></row><row><name>Jack</name></row></root>' );
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> declare
      2          rawXml  xml_doc.doc%type;
      3          xml     xmltype;
      4  begin
      5          -- get the raw XML (as a CLOB)
      6          select doc into rawXml from xml_doc where id = 1;
      7
      8          -- parse it
      9          xml := new xmltype( rawXml );  
    10         -- process the XML...
    11  end;
    12  /
    PL/SQL procedure successfully completed.
    SQL>The variable xml in the sample code is the XML DOM object. XML functions can be used against it (e.g. to extract values in a tabular row and column structure).
    Note that the CLOB needs to contain a valid XML. An XML containing XML fragments is not valid and cannot be parsed. E.g.
    SQL> declare
      2          xml     xmltype;
      3  begin
      4          -- attemp to parse fragments
      5          xml := new xmltype( '<row><name>John</name></row>  <data><column>Name</column></data>' );
      6  end;
      7  /
    declare
    ERROR at line 1:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00245: extra data after end of document
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 301
    ORA-06512: at line 5This XML contains 2 fragments. A row structure and a data structure. It is not a valid XML and as such cannot be parsed. If a root tag is used to encapsulate these 2 fragments, then it will be a valid XML structure.
    In the development, I need to take into consideration performance. We are using Oracle 10, but we could migrate to Oracle 11 if necessary.Have not run into any XML performance problems specifically - and am using it extensively. Even large XMLs (10's of 1000's of elements) parse pretty fast.

  • Split XML files with XSL result document

    Hi All,
    I have below xml file...
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <T0020
    xsi:schemaLocation="http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.safersys.org/namespaces/T0020V1">
    <INTERFACE>
    <NAME>SAFER</NAME>
    <VERSION>04.02</VERSION>
    </INTERFACE>
    <TRANSACTION>
    <VERSION>01.00</VERSION>
    <OPERATION>REPLACE</OPERATION>
    <DATE_TIME>2009-09-01T00:00:00</DATE_TIME>
    <TZ>CT</TZ>
    </TRANSACTION>
    <IRP_ACCOUNT>
    <IRP_CARRIER_ID_NUMBER>274845</IRP_CARRIER_ID_NUMBER>
    <IRP_BASE_COUNTRY>US</IRP_BASE_COUNTRY>
    <IRP_BASE_STATE>AR</IRP_BASE_STATE>
    <IRP_ACCOUNT_NUMBER>55002</IRP_ACCOUNT_NUMBER>
    <IRP_ACCOUNT_TYPE>I</IRP_ACCOUNT_TYPE>
    <IRP_STATUS_CODE>100</IRP_STATUS_CODE>
    <IRP_STATUS_DATE>2007-11-06</IRP_STATUS_DATE>
    <IRP_UPDATE_DATE>2009-08-03</IRP_UPDATE_DATE>
    <IRP_NAME>
    <NAME_TYPE>LG</NAME_TYPE>
    <NAME>A P SUPPLY CO</NAME>
    <IRP_ADDRESS>
    <ADDRESS_TYPE>PH</ADDRESS_TYPE>
    <STREET_LINE_1>1400 N OATS</STREET_LINE_1>
    <STREET_LINE_2/>
    <CITY>TEXARKANA</CITY>
    <STATE>AR</STATE>
    <ZIP_CODE>71854</ZIP_CODE>
    <COUNTY>MILLER</COUNTY>
    <COLONIA/>
    <COUNTRY>US</COUNTRY>
    </IRP_ADDRESS>
    <IRP_ADDRESS>
    <ADDRESS_TYPE>MA</ADDRESS_TYPE>
    <STREET_LINE_1>P O BOX 1927</STREET_LINE_1>
    <STREET_LINE_2/>
    <CITY>TEXARKANA</CITY>
    <STATE>AR</STATE>
    <ZIP_CODE>75504</ZIP_CODE>
    <COUNTY/>
    <COLONIA/>
    <COUNTRY>US</COUNTRY>
    </IRP_ADDRESS>
    </IRP_NAME>
    </IRP_ACCOUNT>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    </T0020>
    and i want to take this xml file and split it into multiple files through java code like this ...
    File1.xml
    <T0020>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    </T0020>
    File2.xml
    <T0020>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    <IRP_ACCOUNT> ..... </IRP_ACCOUNT>
    </T0020>
    so i have applied following xslt ...
    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.safersys.org/namespaces/T0020V1" version="2.0">
    <xsl:output method="xml" indent="yes" name="xml" />
    <xsl:variable name="accounts" select="t:T0020/t:IRP_ACCOUNT" />
    <xsl:variable name="size" select="10" />
    <xsl:template match="/">
    <xsl:for-each select="$accounts[position() mod $size = 1]">
    <xsl:variable name="filename" select="resolve-uri(concat('output/',position(),'.xml'))" />
    <xsl:result-document href="{$filename}" format="xml">
    <T0020>
    <xsl:for-each select=". | following-sibling::t:IRP_ACCOUNT[position() < $size]">
    <xsl:copy-of select="." />
    </xsl:for-each>
    </T0020>
    </xsl:result-document>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Now i want to apply this XSL to xml through Java Code...
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Source xslSource = new StreamSource(xslFilePath);
    Transformer trans = tFactory.newTransformer(xslSource);
    trans.transform(new StreamSource(xmlFileName), new StreamResult( ????));
    here how can i map new StreamResult( ) input parameter with xsl Result document argument ??
    Please help me.....
    Or Can you give me a link of Example which use result document and Java transform method to Output multiple doucment ??
    Here new StreamResult take only 1 file as to be transformed ....

    hi Tejas ,
    I have done as you said but now able to generate multiple xml file .
    I am giving you the xsl file i have used ....
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.safersys.org/namespaces/T0020V1" version="2.0">
         <xsl:output method="xml" indent="yes" name="xml" />
         <xsl:variable name="accounts" select="t:T0020/t:IRP_ACCOUNT" />
         <xsl:variable name="size" select="5" />
         <xsl:template match="/">
              <xsl:for-each select="$accounts[position() mod $size = 1]">
                   <xsl:variable name="filename" select="concat(position(),'.xml')" />
                        <xsl:result-document href="{$filename}" format="xml">
                             <T0020>
                                  <xsl:for-each select=". | following-sibling::t:IRP_ACCOUNT[position() < $size]">
                                       <xsl:copy-of select="." />
                                  </xsl:for-each>                              
                             </T0020>
                        </xsl:result-document>                    
              </xsl:for-each>
         </xsl:template>
    </xsl:stylesheet>
    and i have done transformation like this ...
    Transformer trans = tFactory.newTransformer(xslSource);
    trans.transform(new StreamSource(xmlFileName), new DOMResult());
    but not getting any result .
    Can you please help me out ?
    - Nisarg

  • Using a xml parser with jbuilder

    I'm using jbuilder and the required librairies I've just added require me to add an XML parser to the path. I've just downloaded one from www.apache.org.
    How do I incorporate this parser into my project. I need to use the following packages but I'm not sure how I can put everything together.
    If you understand what my problem is please help. Thanks , B.
    import org.w3c.dom.Document;
    import org.w3c.dom.DOMException;

    Go to tools | configure libraries.
    click the new button on the left
    Type in the name you want the library to be identified with (XML Parser or something)
    Choose the location (this determines how many people and projects have access to the libraries)
    Click the add button and find the *.jar files.
    Ok back out of the dialogs
    Now select the Project Properties (or default props to have the library available to all projects, not recommended tho)
    Select the paths tab
    Click Add and select the Library you added in the earlier steps.
    If you have any probs, www.borland.com has heaps of stuff on configuring libraries

  • Displaying XML hierarchy with XSL

    HI Gentlemen,
    I have an XML subtree and an XSL stylesheet with the following cardinality:
    [scheinarten_liste]
    [scheinart]+
    [scheinuntergruppen_liste]*
    [scheinuntergruppe]+
    Now, when the lower two elements are missing, then the pure hierarchical representation no longer feels well and delivers a mess. However, the <ul>..<li> representation is very stable and completely insensitive to missing elements. I tried this by playing fast and loose with the XML: commenting/uncommenting different parts of the it--it was always working correctly.
    Below is a working code excerpt with solid balls in a single table cell.
    The XML subtree:
        <scheinarten_liste V="1">                                                                                            
        <scheinart V="20" S="1.2.276.0.76.5.235" SV="1.03"> 
         <scheinuntergruppen_liste V="1">
           <scheinuntergruppe V="0101" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
           <scheinuntergruppe V="0102" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
           <scheinuntergruppe V="0103" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
           <scheinuntergruppe V="0104" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
         </scheinuntergruppen_liste>
          </scheinart>                                                       
          <scheinart V="42" S="1.2.276.0.76.5.235" SV="1.03"> 
         <scheinuntergruppen_liste V="1">
           <scheinuntergruppe V="23" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
           <scheinuntergruppe V="24" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
           <scheinuntergruppe V="26" S="1.2.276.0.76.3.1.1.5.1.19" SV="1.03"/>
         </scheinuntergruppen_liste>
          </scheinart>                                                         
        </scheinarten_liste>                                                                                            The XSL stylesheet (HTML body):
    <table border="1">
    <th>Scheinarten-Liste</th>
    <tr>
    <td>
    <xsl:for-each select="pe:bedingung/pe:scheinarten_liste">
      <ul type="disc">
        <li><xsl:text>Listentyp: </xsl:text><xsl:value-of select="@V"/></li>
        <xsl:for-each select="pe:scheinart">
          <ul type="disc">
            <li><xsl:text>Scheinart: </xsl:text><xsl:value-of select="@V"/></li>
            <xsl:for-each select="pe:scheinuntergruppen_liste">
              <ul type="disc">
             <li><xsl:text>Typ der Untergruppen: </xsl:text><xsl:value-of select="@V"/></li>
                <xsl:for-each select="pe:scheinuntergruppe">
                  <ul type="disc">
                 <li><xsl:text>Untergruppe: </xsl:text><xsl:value-of select="@V"/></li>
                  </ul>
                </xsl:for-each>
              </ul>
            </xsl:for-each>
          </ul>
        </xsl:for-each>
      </ul>
    </xsl:for-each>
    </td>
    </tr>
    </table>My question is: Does anybody know a solution to put the hierarchical levels into consecutive table cells with <tr>..<td>? I tried a lot of arrangements but I experienced that when re-executing a nested <xsl:for-each> loop, a new table cell was opened--erroneously.
    With this in mind, I could then dismiss the solid balls and the nested list structure would look like normal nested <rowspan> output.
    Thank you, kind regards
    Miklos HERBOLY

    You should be able to increase performance by caching Templates objects in memory as a previous post suggested.
    Here is some untested code:public final class TransformerCache
         private static Map cache = new Vector();
         private TransformerCache(){}
         public static Transformer getTransformer( String filename )
              if( ! cache.containsKey( filename ) )
                   TransformerFactory tf = TransformerFactory.newInstance();
                   Templates template = tf.newTemplates( new StreamSource( filename ) );
                   cache.put( filename, template );     
              return ( ( Templates ) cache.get( filename ) ).newTransformer();
    }This aproach works in a clustered environment, just bear in ming that there will be an instance of the cache on each server instance (virtual machine).

  • XML Parsing with Tags increasing in no's

    I have an XML that I am recieving it from other system like below :
    <ResultSet>
      <ERROR_CODE_ID>0</ERROR_CODE_ID>
      <ERROR_DESCRIPTION>Success</ERROR_DESCRIPTION>
    <Rows>
    <Row1>
      <RATE_EFFECTIVE_DT>2013-08-24
    00:00:00.0</RATE_EFFECTIVE_DT>
    <INDEX_NAME>LN-EBOR-7D-AED              
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>7D</TERM>
      <TERM_NO>7</TERM_NO>
      <TERM_PERIOD>D</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.15430000</RATE>
    </Row1>
    <Row2>
      <RATE_EFFECTIVE_DT>2013-08-26
    00:00:00.0</RATE_EFFECTIVE_DT>
      <INDEX_NAME>LN-EBOR- 1M-AED  
               </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>1M</TERM>
      <TERM_NO>1</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.52430000</RATE>
    </Row2>
    <Row3>
      <RATE_EFFECTIVE_DT>2013-08-25
    00:00:00.0</RATE_EFFECTIVE_DT>
    <INDEX_NAME>LN-EBOR-2M-AED              
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>2M</TERM>
      <TERM_NO>2</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.66710000</RATE>
    </Row3>
    <Row4>
      <RATE_EFFECTIVE_DT>2013-08-24
    00:00:00.0</RATE_EFFECTIVE_DT>
      <INDEX_NAME>LN-EBOR-
    3M-AED             
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>3M</TERM>
      <TERM_NO>3</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.86140000</RATE>
    </Row4>
    <Row5>
      <RATE_EFFECTIVE_DT>2011-05-23
    00:00:00.0</RATE_EFFECTIVE_DT>
      <INDEX_NAME>LN-EBOR-
    4M-AED             
    </INDEX_NAME>
      <TYPE>LN</TYPE>
      <RATE_TYPE>EBOR</RATE_TYPE>
      <TERM>4M</TERM>
      <TERM_NO>4</TERM_NO>
      <TERM_PERIOD>M</TERM_PERIOD>
      <CCY>AED</CCY>
      <RATE>0.0</RATE>
    </Row5>
    </Rows>
    </ResultSet>
    The data is comming in multiple row tag with Row1,Row2,Row3...so on.
    I am not able to parse the XML with Row1,Row2..etc. I need some help.

    Do you want to do this using Oracle database (which version?), or some other tools ?

  • XML Parsing with Java - Only some attributes have start and end tags

    Hello,
    I am trying to interpret the XML response from a server after a HTTP request is sent to it. I have modified an example off Wikipedia below to give an example of what it looks like.
    Example XML:
    <Asset name="bread" prep_time="5 mins" cook_time="3 hours">
    <Attribute name="Ingredient: ">Flour</Attribute>
    <Attribute name="Ingredient: ">Water</Attribute>
    <Attribute name="Used in Recipes:" />
    </recipe>
    I have been trying to display the above XML in a format such as:
    name: bread prep_time: 5 mins cook_time: 3 hours
    Ingredient: Flour
    Ingredient: Water
    Used in Recipes:
    Right now I have been trying to do it manually using indexOf and substring of the XML text, but I would like to find a better way of doing this. I have found some examples online that show had to deal with cases such as
    <person>
    <first>Kiran</first>
    <last>Pai</last>
    <age>22</age>
    </person>
    but I do not know what to do when I encounter something like the last item, when there are no "Used in Recipe" items, and it ends with a />, instead of an ending tag </Attribute>.
    Are there any suggestions as to how to handle the example XML code that I have posted?
    Any help would be appreciated. Thanks.

    jtahlborn wrote:
    Tolls wrote:
    I suppose so, but since the idea is to turn it into text in a different format, XSLT strikes me as a better fit than hand crafting it.i agree if the end goal is formatted text. however, i wasn't sure if the OP was just writing some test code to figure out how to access the data or if the formatted text was the final desired output.No, true. It is open to interpretation.
    jschell wrote:
    (Quoting the same bit)
    As long as one is mindful of the potential performance and maintenance impacts of course.Again, it depends what he's doing...true. I was making some assumptions, since (as usual) we don't really know the requirements beyond a base technical one (ie "I have this, and I need it to look like this"). In general, though, if you have XML data and you need it formatted differently then I'd say your first port of call ought to be transformation.
    As for maintenance, I'd say it's easier to maintain a stylesheet than to modify Java, which is why I say it ought to be the start point.
    Of course, YMMV.

  • XML Parsing with namespace

    Hi All,
    I have a requirement to convert XML to itab to be processed further.
    I couldn't parse the XML which contains ns0 (namespace?) as following:
    <ns0:OrderNo>887140</ns0:OrderNo>
    <ns0:CPROD>BD</ns0:CPROD>
    <ns0:CURR>USD</ns0:CURR>
    I'm able to parse If I remove the namespace ns0 from the file as following:
    <OrderNo>887140</OrderNo>
    <CPROD>BD</CPROD>
    <CURR>USD</CURR>
    The thing is the XML file will always come with the namespace ns0.
    I'm using IF_IXML, IF_IXML_STREAM_FACTORY, IF_IXML_ISTREAM, IF_IXML_PARSER, IF_IXML_DOCUMENT to parse the XML.
    Any idea on how to overcome this?
    Thanks,
    Victor.

    Hello Victor,
    fine. I am glad, I could help you.
    Just one note to XSLT Transformations: When using them, you got even the ability to map directly to internal abap tables:
    CALL TRANSFORMATION ZXSLT_YOUR_TRANSFORMATION
      SOURCE XML l_xmlstring
      RESULT DATA = lt_data.
    You just need to transform you xml to the asx:abap name space and that's it
    Look at Re: Help needed XML to Internal table and vice versa, where I show a simple example, how this works.
    Kind regards,
    Hendrik

  • XML parsing with digester

    Hi all,
    I'm trying to parse the following xml document:
    <?xml version="1.0" encoding="UTF-8"?>
    <map>
         <entry key='PAGE2.SNOME'>
              <bean key='nomeCliente'>field</bean>
         </entry>
         <entry key='PAGE3.TIPO_CONSTRUCAO'>
              <bean key='tipoConstrucao'>radio</bean>
         </entry>
    </map>with Digester. I'm trying to create a Map that holds Maps as Objects. My first approach was:
    Digester digester = new Digester();
    digester.addObjectCreate("map", HashMap.class);
    digester.addObjectCreate("map/entry", HashMap.class);
    digester.addCallMethod("map/entry", "put", 2);
    digester.addCallParam("map/entry", 0, "key");
    digester.addCallMethod("map/entry/bean", "put", 2);
    digester.addCallParam("map/entry/bean", 0, "key");
    digester.addCallParam("map/entry", 1);But it didn't return the results i expected. Is the order of the instructions wrong? What do i have to change to fix it?
    Hope someone can help me with this.
    Cheers,
    Carlos Ferreira

    Element rootelement = document.getDocumentElement();
    mainNodes = rootelement.getChildNodes();
    for(int i = 0; i<mainNodes.getLength(); i++) {
       Node eachParent = mainNodes.item(i);
       if(!eachParent.getNodeName().equals("#text")) {
          System.out.println(eachParent.getNodeName());
          for(Node child= eachParent.getFirstChild(); child != null; child=child.getNextSibling()) {
             if(!child.getNodeName().equals("#text")) {
                System.out.println(child.getNodeName()+" --- "+child.getFirstChild().getNodeValue());
    }This (your) code will only process the directchild nodes of your rootelement!
    try something like this instead:
    public void processDocument(Document document) {
       processElement(document.getDocumentElement();
    public void processElement(Node node) {
       if(!(node instanceof TextNode)) {
          System.out.println(eachParent.getNodeName());
          NodeList nodeChildren = node.getChildNodes();
          for(int i=0; i<nodeChildren.getLength(); i++) {
             proecessElement(nodeChildren.item(i));
    }

  • XML parsing with DocumentBuilder

    Hi,
    I use to parse an XML document using DocumentBuilder and Document objects.
    When i have within my XML document the following line :
    <value>MY_VALUE</toto>
    How can i get the value "MY_VALUE" using Node objects without searching elements by tag name or criteria ???
    Chris

    Parse document with dom4j parser and get the tag value with xpath.
    http://www.dom4j.org/guide.html

  • Java XML parsing with Xerces in Eclipse using Oxygen problem

    Hey everybody,
    Got me a stickler of a prob here and i'm hoping sum one out there will be able to help. I am trying to parse XML files into JDom objects so i can use them in the rest of my project with ease, but i'm having trouble parsing anything wihtout getting these errors
    Error: URI = /filelocat/personal-schema.xml", Line = "3", : Document root element "personnel", must match DOCTYPE root "null".
    Error: URI = /filelocat/personal-schema.xml", Line = "3", : Document is invalid: no grammar found.
    Error: URI = /filelocat/personal-schema.xml", Line = "3", : cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'personnel'.
    Error: URI = /filelocat/personal-schema.xml", Line = "3", : cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'personnel'.
    The are the files are ones that come in Oxygens samples folder so they should be correct. The code is as follows
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setValidating(true);
    SchemaFactory sFact = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = sFact.newSchema(schemaFile);
    factory.setSchema(schema);
    DocumentBuilder dommer = factory.newDocumentBuilder();          
    Document doco = dommer.parse(xmlFile.getAbsolutePath());None of these errors appears to be fatal, i can still use the doco object and extract the information i require, but i want to understand where the errors are coming from. There must be a parser setting or sumthing i've missed somewhere.
    Can anyone help?
    Any ideas/surgestions/critique welcome.
    Tom

    When we are parsing this xml: "<CustomerInfo><VCID/>77888</CustomerInfo>".
    See comments in following code.
    Element docEle = d.getDocumentElement(); // Returns "CustomerInfo" element node.
    NodeList childNodes2 = docEle.getChildNodes(); // Returns two nodes: <VCID/> element node and 77888 text node.
    Node item4 = childNodes2.item( 0 ); // First node (element node) of the "CustomerInfo" tag. <VCID/>
    Node item5 = childNodes2.item( 1 ); // Second node (text node) of the "CustomerInfo" tag is 77888. Look this text is not child of VCID, it's second child node of "CustomerInfo" tag.
    NodeList childNodes3 = item4.getChildNodes(); // Returns null because <VCID/> node is empty.
    String nodeValue = item5.getNodeValue(); // Returns 77888 ( text node ).               Regards,
    S&#322;awomir Wojtasiak

  • Simple XML parsing with DOM

    I have a XML file i need to parse. Can please someone give me a hint how to do this(please include code). Please note that im a new in XML and my DOM structure knowledge in limited(im confused from all the tutorials).
    XML code:
    <Vitals>
    <Hostname>sometest</Hostname>
    <IPAddr>sometest</IPAddr>
    <Kernel>sometest</Kernel>
    <Uptime>sometest</Uptime>
    <Users>sometest</Users>
    <LoadAvg>sometest</LoadAvg>
    </Vitals>
    <Network>
    <NetDevice>
    <Name>lo</Name>
    <RxBytes>10425010</RxBytes>
    <TxBytes>10425010</TxBytes>
    <Errors>0</Errors>
    <Drops>0</Drops>
    </NetDevice>
    <NetDevice>
    <Name>eth0</Name>
    <RxBytes>627976843</RxBytes>
    <TxBytes>2394415516</TxBytes>
    <Errors>271</Errors>
    <Drops>0</Drops>
    </NetDevice>
    </Network>
    So far ima at this step:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( new File("NewFile.xml") );

    Just as simple text in console.
    Please give me the code.
    Is there any diference in document (DOM) if you create it with DFD or w/h ?
    So far i have this code, but it dosnt work for me(i get nothing as output:
    document = builder.parse( new File("NewFIle.xml") );
    NodeList list = document.getElementsByTagName("coffee");
    // Loop through the list.
    for (int k=0; k < list.getLength(); k++) {
    Node thisCoffeeNode = list.item(k);
    Node thisNameNode = thisCoffeeNode.getFirstChild();
    if (thisNameNode == null) continue;
    if (thisNameNode.getFirstChild() == null) continue;
    if (! (thisNameNode.getFirstChild() instanceof org.w3c.dom.Text)) continue;
    String data = thisNameNode.getFirstChild().getNodeValue();
    System.out.println(data);
    }

Maybe you are looking for