Problem in parsing JMS TextMessages using DOM

Hi
I want to parse JMS TextMessages by using DOM parser.DomBuilder's parse method supports only Strings,input stream in its constructor.
Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
Thanks
Kanth

kanth218 wrote:
Hi
DomBuilder's parse method supports only Strings,input stream in its constructor.This is not true. Have another look at the documentation.
Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
parse(new InputSource(new StringReader(someString)))

Similar Messages

  • Problem in parsing an xml using DOM parser.

    Hi,
        I have created an action block for client.
        it  takes a xml file present on D drive and generates a pdf by parsing the xml file.
        My code was working perfectly fine till yesterday.
    But now i getting , [INFO ]: Error-- Premature end of file.  org.xml.sax.SAXParseException: Premature end of file.
    But xml is perfectly fine. Also the code work from eclipse.
    Need some inputs on this.
    Regards,
    Vishal Jadhav
    Edited by: vishal jadhav on Jan 23, 2009 9:49 AM

    Vishal,
    what exactly did you change? How do you call the action block? What version/Support package/Build of MII do you use?
    Have you see the following thread? There a user had the same message which was caused by missing credentials.
    [https://forums.sdn.sap.com/click.jspa?searchID=21364701&messageID=6756453]
    Michael
    Edited by: Michael Otto on Jan 23, 2009 11:57 AM

  • Problem while parsing xml file using DOM

    I have a xml file NewXML.xml. When I parse it I'm not getting the expected output: I'm trying to get only the value of the "name" tag. When I tried getElementByTagName("name"), I'm not getting the expected result.
    Here is my xml file based on a schema
    <?xml version="1.0" encoding="UTF-8"?>
    <student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NewXMLSchema.xsd">
    <name>john</name>
    <id>1000</id>
    </student>
    Coding:
    public static void main(String argv[])
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    Document document ;
    try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    document = builder.parse( "NewXML.xml" );
    NodeList nodeList = (document.getElementsByTagName("name") );
    System.out.println(nodeList.getLength()+" node list "+nodeList.item(0));
    System.out.println(nodeList.item(0).getNodeValue());
    NodeList nodeList1 = nodeList.item(0).getChildNodes();
    System.out.println(nodeList1.getLength()+" node list "+nodeList1.item(0));
    System.out.println(nodeList1.item(0).getNodeValue());
    When I ran the above coding I got:
    1 node list [name: null]
    null
    1 node list [#text: name]
    name
    What should I do to get the result "john" inorder to change it
    Thanks
    rathi

    System.out.println(nodeList.item(0).getFirstChild().getNodeValue());

  • Parsing an XML using DOM parser in Java in Recursive fashion

    I need to parse an XML using DOM parser in Java. New tags can be added to the XML in future. Code should be written in such a way that even with new tags added there should not be any code change. I felt that parsing the XML recursively can solve this problem. Can any one please share sample Java code that parses XML recursively. Thanks in Advance.

    Actually, if you are planning to use DOM then you will be doing that task after you parse the data. But anyway, have you read any tutorials or books about how to process XML in Java? If not, my suggestion would be to start by doing that. You cannot learn that by fishing on forums. Try this one for example:
    http://www.cafeconleche.org/books/xmljava/chapters/index.html

  • 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;

  • Problem in parsing white spaces using if_ixml_parser

    Hello People,
    I have a problem in parsing XML file in one of my programs.
    The program uses the method get_value( ) of class if_ixml_node to fetch a value. In the XML file when the value is spaceA, then after parsing, the value fetched is A and not spaceA.
    Is there any way to fetch the white spaces also?
    Here is the sample tag. The value inside the tags is " A" and after parsing I get "A" the blank is ignored.
    <ns1:IndiceCible> A</ns1:IndiceCible>
    DATA : l_node_fils       TYPE REF TO if_ixml_node.
    indice_val = l_node_fils->get_value( ).
    In some XML parsing forums I saw that if we add the option as shown below, then the parsing works properly. But this did not work in my case.
    <ns1:IndiceCible xml:space="preserve"> A</ns1:IndiceCible>
    The input XML file is as follows.
    <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><env:Flow xmlns:env="http://xml.inetpsa.com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:MessageID>0414
    2636F4888F4B4A579A21E10000000A52931C</env:MessageID><env:From>R3P INTERFACES</env:From><env:To>SAP</env:To><env:TimeStamp>2010-03-04T14:26:36.672+01:00</env:TimeStamp></env:Flow></SOAP-ENV:Header><SOAP-ENV:Body><env:Response xmlns:env="http://xml.inetpsa.
    com/Structure/Informatique/DeveloppementSI/ReferentielEchange"><env:Values><ns1:ListeTranscodifications xmlns:ns1="http://xml.inetpsa.com/ProduitProcess/Produit/Transcodification"><ns1:Transcodification id="1 "><ns1:Statut>KO</ns1:Statut><ns1:Message>ERRO
    R : Indice incorrect</ns1:Message><ns1:ReferenceCible>969099979A</ns1:ReferenceCible><ns1:IndiceCible> A</ns1:IndiceCible><ns1:ColoreCible>SS_TEINTE</ns1:ColoreCible></ns1:Transcodification></ns1:ListeTranscodifications></env:Values><env:Status><env:Code>
    0</env:Code><env:Label></env:Label></env:Status></env:Response></SOAP-ENV:Body></SOAP-ENV:Envelope>
    Regards,
    Praveen

    use IF_XML_PARSER~CL_ADD_PRESERVE_SPACE_ELEMENT method:
    PARAMETERS preserve TYPE flag AS checkbox.
      DATA lo_ixml          TYPE REF TO if_ixml.
      DATA lo_streamfactory TYPE REF TO if_ixml_stream_factory.
      DATA lo_parser        TYPE REF TO if_ixml_parser.
      DATA lo_istream       TYPE REF TO if_ixml_istream.
      DATA lo_document      TYPE REF TO if_ixml_document.
      DATA lo_node          TYPE REF TO if_ixml_node.
      DATA l_node_value          TYPE string.
      lo_ixml = cl_ixml=>create( ).
      lo_streamfactory = lo_ixml->create_stream_factory( ).
      lo_istream = lo_streamfactory->create_istream_string(
            string = '<?xml version="1.0" encoding="iso-8859-1"?><DATA>  WAAA</DATA>' ).
      lo_document = lo_ixml->create_document( ).
      lo_parser = lo_ixml->create_parser( stream_factory = lo_streamfactory
                                          istream        = lo_istream
                                          document       = lo_document ).
    IF preserve = 'X'.
      lo_parser->ADD_PRESERVE_SPACE_ELEMENT( ). "<========= HERE
    ENDIF.
      lo_parser->parse( ).
      lo_node = lo_document->find_from_name( name = 'DATA').
      l_node_value = lo_node->get_value( ).
      ASSERT ( preserve = 'X' AND l_node_value = '  WAAA' )
            OR ( preserve = space AND l_node_value = 'WAAA' ).

  • Parsing .xsd files using DOM

    Hi,
    I am trying to parse a xsd file using DOM. The xsd has several nodes like
    <xsd:complexType name="AccountLocate">
    I want to extract the strings AccountLocate and AccountCategory and use them for further processing.
    The hierarchy of the nodes is created without issues, but when I try to view the name and value of each node using getNodeName() and getNodeValue() method the node name I get and node value is as follows:
    NODE-NAME NODE-VALUE NODE-TYPE
    xsd:complexType null 1 //corresponds to the xsd:complexType node
    #text 3 //corresponds to the AccountLocate node
    Is there anyway (any DOM method for example) by which I can isolate the name AccountLocate?
    Thanks and regards,
    Prabal

    Which parser is used for parsig?
    With the DocumentBuilder parser set:
    DocumentBuilderFactory factory
    = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);For parsing with the javax.xml.xpath.XPath class set the NamespaceContext on the XPath object.

  • Problem Encountered in JMS adapter using SEEBURGER module

    While testing the receiver JMS adapter for XML to EDI conversion using Seeburger module, I am facing errors.
    <b>1. The error encountered is</b> :
    Error while processing message '4720bc32-2dfc-03d8-0000-00000a2050d3';  detailed error description: java.lang.NullPointerException at com.sap.aii.adapter.jms.core.connector.SendContextImpl.send(SendContextImpl.java:43) ...
    <u>SEEBURGER BICXIADAPTER</u> --- Conversion of synchronous request from module chain ended with errors ---Error: [Error:ID=2061;LEVEL=1] XMLDocReader moveNext(): Cannot move to next trigger : Error in line 1: <u>XML file should begin with white spaces or <. (Found char :U(Hex :85</u>). DESCRIPTION: XMLDocReader Exception: Not able to move to next trigger [not specified] - trigger may not right set.
    <b>2. The targer PAYMUL xml is as follows</b> :
    ( At receiver channel, the above should be converted to EDI-Paymul using the Seeburger Module)
    <u>PAYMUL XML</u>
      <?xml version="1.0" encoding="UTF-8" ?>
    - <LIST>
    - <S_UNA>
      <D_DELIMITER>:+.? '</D_DELIMITER>
      </S_UNA>
    - <S_UNB>
    - <C_S001>
      <D_0001>UNOA</D_0001>
      <D_0002>2</D_0002>
      </C_S001>
    - <C_S002>
      <D_0004>SAPDM</D_0004>
      <D_0007>ZZ</D_0007>
      </C_S002>
    - <C_S003>
      <D_0010>000000000000</D_0010>
      <D_0007>55</D_0007>
      </C_S003>
    - <C_S004>
      <D_0017>070201</D_0017>
      <D_0019>1150</D_0019>
      </C_S004>
      <D_0020>01945678912345</D_0020>
    - <S_UNH>
      <D_0062>1</D_0062>
    - <C_S009>
      <D_0065>PAYMUL</D_0065>
      <D_0052>D</D_0052>
      <D_0054>96A</D_0054>
      <D_0051>UN</D_0051>
      <D_0057>FUN01G</D_0057>
      </C_S009>
    - <S_BGM>
    - <C_C002>
      <D_1001>452</D_1001>
      </C_C002>
      <D_1004>01945678912345</D_1004>
      <D_1225>9</D_1225>
      </S_BGM>
    - <S_DTM>
    - <C_C507>
      <D_2005>137</D_2005>
      <D_2380>20070201</D_2380>
      <D_2379>102</D_2379>
      </C_C507>
      </S_DTM>
    - <G_SSG4>
    - <S_LIN>
      <D_1082>1</D_1082>
    - <S_DTM>
    - <C_C507>
      <D_2005>203</D_2005>
      <D_2380>20070201</D_2380>
      <D_2379>102</D_2379>
      </C_C507>
      </S_DTM>
    - <S_RFF>
    - <C_C506>
      <D_1153>ACK</D_1153>
      <D_1154>01945678912345</D_1154>
      </C_C506>
      </S_RFF>
    - <S_RFF>
    - <C_C506>
      <D_1153>AEK</D_1153>
      <D_1154>01945678912345</D_1154>
      </C_C506>
      </S_RFF>
    - <S_BUS>
      <D_3279>IR</D_3279>
    - <C_C551>
      <D_4383>UGI</D_4383>
      </C_C551>
      </S_BUS>
    - <G_SSG5>
    - <S_MOA>
    - <C_C516>
      <D_5025>9</D_5025>
      <D_5004>5000</D_5004>
      <D_6345>EUR</D_6345>
      </C_C516>
      </S_MOA>
      </G_SSG5>
    - <G_SSG6>
    - <S_FII>
      <D_3035>OR</D_3035>
    - <C_C078>
      <D_3194>ES921998500000000012</D_3194>
      <D_6345>EUR</D_6345>
      </C_C078>
    - <C_C088>
      <D_3433>ABNAES17000</D_3433>
      <D_1131>25</D_1131>
      <D_3055>5</D_3055>
      </C_C088>
      <D_3207>ES</D_3207>
      </S_FII>
      </G_SSG6>
    - <G_SSG7>
    - <S_NAD>
      <D_3035>OY</D_3035>
    - <C_C080>
      <D_3036>XYZ CORPORATION LTD</D_3036>
      </C_C080>
    - <C_C059>
      <D_3042>XX</D_3042>
      </C_C059>
      <D_3164>XX</D_3164>
      <D_3207>ES</D_3207>
      </S_NAD>
      </G_SSG7>
    - <G_SSG11>
    - <S_SEQ>
    - <C_C286>
      <D_1050>1</D_1050>
      </C_C286>
    - <S_MOA>
    - <C_C516>
      <D_5025>9</D_5025>
      <D_5004>5000</D_5004>
      <D_6345>EUR</D_6345>
      </C_C516>
      </S_MOA>
    - <S_DTM>
    - <C_C507>
      <D_2005>227</D_2005>
      <D_2380>2007-02-01</D_2380>
      <D_2379>102</D_2379>
      </C_C507>
      </S_DTM>
    - <S_RFF>
    - <C_C506>
      <D_1153>AIK</D_1153>
      <D_1154>01901234567890</D_1154>
      </C_C506>
      </S_RFF>
    - <S_RFF>
    - <C_C506>
      <D_1153>CR</D_1153>
      <D_1154>01901234567890</D_1154>
      </C_C506>
      </S_RFF>
    - <S_FCA>
      <D_4471>13</D_4471>
      </S_FCA>
    - <G_SSG12>
    - <S_FII>
      <D_3035>BF</D_3035>
    - <C_C078>
      <D_3194>AT921998500000000011</D_3194>
      <D_6345>EUR</D_6345>
      </C_C078>
    - <C_C088>
      <D_3433>ABNAAT14000</D_3433>
      <D_1131>25</D_1131>
      <D_3055>5</D_3055>
      </C_C088>
      <D_3207>ES</D_3207>
      </S_FII>
      </G_SSG12>
    - <G_SSG13>
    - <S_NAD>
      <D_3035>BE</D_3035>
    - <C_C080>
      <D_3036>ABC CORPORATION 1</D_3036>
      </C_C080>
    - <C_C059>
      <D_3042>XX</D_3042>
      </C_C059>
      <D_3164>XX</D_3164>
      <D_3207>ES</D_3207>
      </S_NAD>
      </G_SSG13>
    - <G_SSG16>
    - <S_PRC>
    - <C_C242>
      <D_7187>11</D_7187>
      </C_C242>
    - <S_FTX>
      <D_4451>PMD</D_4451>
    - <C_C108>
      <D_4440>SENDERPN1</D_4440>
      </C_C108>
      </S_FTX>
      </S_PRC>
      </G_SSG16>
      </S_SEQ>
      </G_SSG11>
      </S_LIN>
      </G_SSG4>
    - <S_CNT>
    - <C_C270>
      <D_6069>2</D_6069>
      <D_6066>1</D_6066>
      </C_C270>
      </S_CNT>
    - <S_UNT>
      <D_0074>1</D_0074>
      <D_0062>1</D_0062>
      </S_UNT>
      </S_UNH>
    - <S_UNZ>
      <D_0036>1</D_0036>
      <D_0020>01945678912345</D_0020>
      </S_UNZ>
      </S_UNB>
      </LIST>
    <b>3. The module parameters for Seeburger inputs :</b>
    ( In receiver communication channel)
    <b>Processing Sequence</b>
    localejbs/CallBicXIRaBean               Local Ent Bean     x2e_bic_paymul
    SAP XI JMS Adapter/ConvertMessageToBinary     Local Ent Bean     convert_XI2Bin
    SAP XI JMS Adapter/SendBinarytoXIJMSService     Local Ent Bean     
                    exit
    <b>Module Key</b>
    x2e_bic_paymul     destSourceMsg     MainDocument
    x2e_bic_paymul     destTargetMsg     MainDocument
    x2e_bic_paymul     logAttID          ConverterLog
    x2e_bic_paymul     mappingName     See_X2E_PAYMUL_UN_D96A
    x2e_bic_paymul     newLine          true
    x2e_bic_paymul     saveSourceMsg     XMLEDI

    Hi,
    Check Below links,
    /people/bla.suranyi/blog/2006/06/08/sap-xi-supports-edifact
    http://www.seeburger.it/fileadmin/it/pdf/2005_04_sapphire_Ferrero_transcript.pdf
    http://www.seeburger.com/fileadmin/com/pdf/Butler_Group_SEEBURGER_Technology_Audit.pdf
    http://www.seeburger.com/fileadmin/com/pdf/AS2_General_Overview.pdf
    SAP Adapters
    Regards,
    Phani

  • 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

  • Displaying a matrix using DOM

    hi group,
    this is satya chowdhury .i am facing some problem in how to parse a matrix using dom.the xml file is as follows:-
    <?xml version="1.0" ?>
    - <matrix>
    <rows>4</rows>
    <columns>4</columns>
    - <row>
    <column>11</column>
    <column>12</column>
    <column>13</column>
    <column>14</column>
    </row>
    - <row>
    <column>21</column>
    <column>22</column>
    <column>23</column>
    <column>24</column>
    </row>
    - <row>
    <column>31</column>
    <column>32</column>
    <column>33</column>
    <column>34</column>
    </row>
    - <row>
    <column>41</column>
    <column>42</column>
    <column>43</column>
    <column>44</column>
    </row>
    </matrix>
    and the program is as follows
    import java.io.File;
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.ErrorHandler;
    public class Matadd
         static Document doc;
    static int mat[][]=new int[0][0];
         public static void main(String arg[])
              DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
              try
              DocumentBuilder builder=factory.newDocumentBuilder();
              builder.setErrorHandler(new Terror());
              doc=builder.parse(new File("mat.xml"));
              Element root=doc.getDocumentElement();
              NodeList list=doc.getElementsByTagName("row");
              int i=list.getLength();
              System.out.println("THE NO.OF ROWS IN THE GIVEN MATRIX--->"+i);
              NodeList list1=doc.getElementsByTagName("column");
              int j=list.getLength();
              System.out.println("THE NO.OF COLUMNS IN THE GIVEN MATRIX--->"+j);
    for(int row=0;row<i;row++)
    for(int col=0;col<j;col++)
         Node node=list1.item(col).getLastChild();
              System.out.println(""+node.getNodeValue());
              catch(SAXException e)
              catch(IOException e)
              catch(ParserConfigurationException e)
              static class Terror implements ErrorHandler
                                  public void fatalError(SAXParseException e)
                                       System.out.println("error:"+e);
                             public void error(SAXParseException e)
                                       System.out.println("error:"+e);
                                  public void warning(SAXParseException e)
                                            System.out.println("error:"+e);
    BUT IS IS NOT ITERATING ALL THE ROWS.PLZ HELP ME.I HAVE TO SUBMIT THE ASSIGNMENT TODAY.
    BYE
    SATYABRATA
    [email protected]

    i have modified ur cod e..this is working..i have created on recursive function that will iterate through ur colum values...
    any comments please let me knoe
    reagards
    shanu
    [email protected]
    import java.io.File;
    import java.io.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.FactoryConfigurationError;
    import javax.xml.parsers.ParserConfigurationException;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.ErrorHandler;
    * @author sm23772
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class SimpleParse {
         static Document doc;
         static int mat[][]=new int[0][0];
         public static void main(String[] args) {
              DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
              try
              DocumentBuilder builder=factory.newDocumentBuilder();
              doc=builder.parse(new File("test.xml"));
              Element root=doc.getDocumentElement();
              NodeList list=doc.getElementsByTagName("row");
              int i=list.getLength();
              System.out.println("THE NO.OF ROWS IN THE GIVEN MATRIX--->"+i);
              NodeList list1=doc.getElementsByTagName("column");
              int j=list.getLength();
              System.out.println("THE NO.OF COLUMNS IN THE GIVEN MATRIX--->"+j);
              for (Node child = root.getFirstChild();
    child != null;
    child = child.getNextSibling())
    if(child.getNodeName().equals("row"))
         getValues(child); //calling my recursive funciton
    /************** instead of this i have made small funciton ******************/
              /*for(int row=0;row<i;row++)
              for(int col=0;col<j;col++)
              Node node=list1.item(col).getLastChild();
              System.out.println(""+node.getNodeValue());
    System.out.println("");
              catch(Exception e)
                   System.out.println(e);
    public static void getValues(Node start)
    if(start.getNodeName().equals("column"))
    System.out.println(start.getFirstChild().getNodeValue());
    for (Node child = start.getFirstChild();
    child != null;
    child = child.getNextSibling())
         getValues(child);
    }

  • Generating XMLs from CSVs using DOM parser......

    Hi,
    I am trying to generate XMLs from CSV files using DOM parser. XMLs are getting generated but the problem is that i am using Encoding "ISO-8859-1" but XMLs are getting generated in UTF-8 encoding.
    Please refer to the code below and advice. (where are the code tags gone ????? )
    Source domSource = new DOMSource(document);
    ByteArrayOutputStream xmlStream = new ByteArrayOutputStream();
    Result result = new StreamResult(xmlStream);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.transform(domSource, result);
    xmlStream.close();
    generatedXml = new String(xmlStream.toByteArray(), "*ISO-8859-1*");

    Use transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1") to specify the character set.

  • Parsing xml using DOM parser in java

    hi there!!!
    i don have much idea about parsing xml.. i have an xml file which consists of details regarding indentation and spacing standards of C lang.. i need to read the file using DOM parser in java n store each of the attributes n elements in some data structure in java..
    need help as soon as possible!!!

    DOM is the easiest way to parse XML document, google for JDOM example it is very easy to implement.
    you need to know what is attribute, what is text content and what is Value in XML then easily you can parse your document with dom (watch for space[text#] in your XML document when you parse it).
    you get root node then nodelist of childs for root then go further inside, it is easy believe me.

  • Need to retrieve all the node values of xml using DOM parser..pls help

    I want to fetch each node value in this xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <Main>
    <AAAAA>
    <ES>ESValue</ES>
    <EI>EIValue</EI>
    </AAAAA>
    <BBBBB>
    <SIP>
    <ST>STValue</ST>
    <TB>TBValue</TB>
    <PM>PMValue</PM>
    <VIP>
    <CARP>
    <AN1>AN1Value</AN1>
    <BN>BNValue</BN>
    </CARP>
    <DARP>
    <SA>
    <AN2>AN2Value</AN2>
    <CN>CNValue</CN>
    </SA>
    </DARP>
    </VIP>
    </SIP>
    </BBBBB>
    </Main>
    output should be the inner text values of diffrent nodes that contain some values..
    i.e
    output:
    ESValue
    EIValue
    STValue
    TBValue
    PMValue
    AN1Value
    BNValue
    AN2Value
    CNValue
    so that i can use thses node values and put it them in database...

    pls check the above xml file in proper redable order...I need to parse using DOM and fetch node values that are present...
    <?xml version="1.0" encoding="UTF-8"?>
    <Main>
        <AAAAA>
            <ES>ESValue</ES>
            <EI>EIValue</EI>
        </AAAAA>
        <BBBBB>
            <SIP>
                <ST>STValue</ST>
                <TB>TBValue</TB>
                <PM>PMValue</PM>
                <VIP>
                    <CARP>
                        <AN1>AN1Value</AN1>
                        <BN>BNValue</BN>
                    </CARP>
                    <DARP>
                        <SA>
                            <AN2>AN2Value</AN2>
                            <CN>CNValue</CN>
                        </SA>
                    </DARP>
                </VIP>
            </SIP>
        </BBBBB>
    </Main>

  • How to ignore empty text element while using DOM to parse xml??

    hi everyone,
    i am using DOM to parse an xml file. But i dont know how to cinfig the DocumentBuilderFactory to ignore empty text elements.
    For example, i have an xml file like this:
    <?xml version="1.0" encoding="UTF-8" ?>
    <root>
        <child>Tom</child>
        <child>Jerry</child>
    </root>I used the following codes to parse:
    String fname = "Tom-and-Jerry.xml";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setIgnoringElementContentWhitespace(true);
    factory.setIgnoringComments(true);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    // Generate a DOM tree from the DOM builder.
    org.w3c.dom.Document dom = builder.parse(new File(fname));
    org.w3c.dom.NodeList list = dom.getChildNodes();
    for (int i=0; i<list.getLength(); i++) {
        System.out.println("Child No."+i);
        System.out.println("NodeName="+list.item(i).getNodeName());
        System.out.println("NodeType="+getType(list.item(i).getNodeType()));
        System.out.println("NodeValue="+list.item(i).getNodeValue());
        System.out.println();
    }The result is not exactly what i want ---- there are 5 children in list!! The 1st, 3rd and 5th are #text and their values are all empty. Only the 2nd and the 4th are the child that i expect.
    It is really troublesome to get all these silly empty texts as sub elements. I tried to get rid of them, but i failed. I just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.
    Anyone can help me? thanks.
    Heavy ZHENG

    I just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.That only does something if the XML has a DTD that enables it to know what whitespace can be ignored and what is significant. The API documentation for the method refers you to this document:
    http://www.w3.org/TR/REC-xml#sec-white-space

  • Update XML using DOM parser

    I am using Dom parser in java to parse xml.I am able to retrive data from xml.Can any one help me in updating an xml when data is modified in the user interface.I am created interface in html with three fields namely UserName , LastLogin, Modified fields.If Admin person wants to modify any of these three fields , those changes should reflect in xml also.
    Thanks
    divya

    Code snippet
    ===========
    OutputFormat outputFormat = new OutputFormat("XML","ISO-8859-1",true);
    outputFormat.setDoctype(null,"emp.dtd")
    It adds the DOCTYPE element but doesnt create the .DTD file.
    <!DOCTYPE ROOT_EL SYSTEM "emp.dtd">
    Any ideas?
    Rgds,
    Seetesh

Maybe you are looking for

  • 64-Bit Windows 7 Load Driver Installation Problem

    I am new to Mac and have recently got my hands on a new 17" MBP. The MBP is a 2011 model dating from about May. Not wanting to step 100% away from Windows I want to install Windows 7 as well and run Mac OS. I have tried installing Windows 7 32-Bit an

  • After Effects: Windows 7: QT32 Server.exe Crashing When Rendering H264

    Hi, I am encountering After Effects on Windows 7 SP1 outputting an "Output Module Failed" when rendering any comp to the desktop as a QT H264(even a new project w/ a comp w/ just a single solid & no effects) in both After Effects 12.1/2 and Media Enc

  • Send Mail step in ready state

    Hello Experts, I am a workflow novice, just starting out. I have copied the standard PO release workflow - WS20000075 and inserted a send mail step before activity "Release of purchase order". This was because I would like to send the PO as a PDF att

  • Where is my New Folder option?

    I bought and dowloaded Lion, but I noticed that I can no longer select New Folder in the Finder File Menu.  The only option I can select is New Smart Folder.  Does anyone know why this change occurred and how I can create a New Folder that is not a S

  • HT201303 Forgot security question answers!

    My brother set up the security questions on my account and forgot them but never told me the answers. What can i do to change them as i cant rent a film with out knowing the answers. Thanks