Parsing XML and Storing values in instance variable

hi,
i'm new to XML.
here i'm trying to parse an XML and store their element data to the instance variable.
in my main method i'm tried to print the instance variable. but it shows "" (ie it print nothing ).
i know the reason, its becas of the the endElement() event generated and it invokes the characters() and assigns "" to the instance variable.
my main perspective is to store the element data in instance variable.
thanks in advance.
praks
import java.io.*;
import java.net.*;
import java.util.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class mysax extends DefaultHandler
     String ctelement;
     CharArrayWriter contents;
     String vname1,vrcbreg1,vaddress1,vcountry1,vtelephone1,vfax1;
     String vname,vrcbreg,vaddress,vcountry,vtelephone,vfax;
     public mysax()
          vname1 = null;
          vrcbreg1 = null;
          vaddress1 = null;
          vcountry1 = null;
          vtelephone1 = null;
          vfax1 = null;
          contents= new CharArrayWriter();
     public void doparse(String url) throws Exception
          SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
ParserAdapter pa = new ParserAdapter(sp.getParser());
pa.setContentHandler(this);
pa.parse(url);          
     public void startElement(String namespace,String localName,String qName,Attributes atts)
          ctelement = localName;     
     public void endElement(String uri,String localName,String qName) throws SAXException
     public void characters(char[] ch,int start, int length) throws SAXException
          try
               if(ctelement.equals("name"))
                    vname = new String (ch,start,length);
                    System.out.println("The method "+vname1);
          }catch (Exception e)
               System.out.println("The exception "+e);
     public static void main(String args[])
          try
          mysax ms = new mysax();
          ms.doparse(args[0]);
          System.out.println("the contents name "+ms.vname1);
          catch(Exception e)
               System.out.println("this is exception at main" +e);
my XML looks like
<coyprofile_result>
<company>     
<name>abcTech</name>
<rcbreg>123456789</rcbreg>
<address>Singapore</address>
<country>sg</country>
<telephone>123456</telephone>
<fax>123155</fax>
</company>
</coyprofile_result>

I believe that the problem has to do with the value you assign to ctelement. You are assigning the value of localName to ctElement, however for the element: <name>...</name> the localname is empty string i.e. "", but qName equals "name". Because you are assigning empty string to ctElement, when you do the comparison in characters of ctElement to "name" it will always be false. So in startElement change it to ctElement = qName; Try it and see if it works. I have produced similar programs and it works for me.
Hope this helps.

Similar Messages

  • How to change value of instance variable and local variable at run time?

    As we can change value at run time using debug mode of Eclipse. I want to do this by using a standalone prgram from where I can change the value of a variable at runtime.
    Suppose I have a class, say employee like -
    class employee {
    public String name;
    employee(String name){
    this.name = name;
    public int showSalary(){
    int salary = 10000;
    return salary;
    public String showName()
    return name;
    i want to change the value of instance variable "name" and local variable "salary" from a stand alone program?
    My standalone program will not use employee class; i mean not creating any instance or extending it. This is being used by any other calss in project.
    Can someone tell me how to change these value?
    Please help
    Regards,
    Sujeet Sharma

    This is the tutorial You should interest in. According to 'name' field of the class, it's value can be change with reflection. I'm not sure if local variable ('salary') can be changed - rather not.

  • Database updation using XML and stored Procedure?

    Hello,
    I want to perform updation in multiple tables using XML files.Please suggest can I do updation using xml and stored procedure.
    If yes then which is more efficient and takes less time.
    1.Updation using xml files only
    2.Updation using xml files with stored procedure.
    3.Stored procedure alone.
    If direct xml and stored procedure communication is possible.then please write how.
    Thanks in advance for any help.

    Here's a sample. The next code drop of the XSQL Servlet will make the easy-to-do from within XSQL Pages:
    package package1;
    import org.w3c.dom.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.query.OracleXMLQuery;
    public class Class1 extends Object {
    public static void main( String[] arg ) throws Exception {
    Connection conn = getConnection();
    CallableStatement ocs = conn.prepareCall("begin ? := App.HotItems('PAUL'); end;");
    ocs.registerOutParameter(1,OracleTypes.CURSOR);
    ocs.execute();
    ResultSet rs = ((OracleCallableStatement)ocs).getCursor(1);
    OracleXMLQuery oxq = new OracleXMLQuery(conn,rs);
    System.out.println(oxq.getXMLString());
    oxq.close();
    rs.close();
    ocs.close();
    conn.close();
    public static Connection getConnection() throws Exception {
    String username = "scott";
    String password = "tiger";
    String dburl = "jdbc:oracle:thin:@localhost:1521:xml";
    String driverClass = "oracle.jdbc.driver.OracleDriver";
    Driver d = (Driver)Class.forName(driverClass).newInstance();
    return DriverManager.getConnection(dburl,username,password);
    null

  • Parse XML and Output to JSP page

    I have a number of XML documents which are all formatted in the same way, just with different information in the fields.
    I wish to parse the XML documents using DOM and output them to an XML page.
    How would i go about doing this?
    If you could write a small example or any websites that you think might help.
    Thanks.

    I have the parsing working but i cant seem to figure out how to get information out of the parsed document and into variables.
    This is a sample of my XML file
    <?xml version="1.0"?>
    <product code="QB-1226-AB">
         <productName>Professional Floodlights</productName>
         <description>PIR floodlights that are designed for professional installation. A faulty light requiring a return visit will cost far more than a quality light does in the first place. 3 year guarantee.</description>
         <price>120</price>
         <manufacturer>Black and Decker</manufacturer>
    </product>I can get the productCode value out without any problems using
    String name = attrs.getValue("code");
    But if i try the same for any of the others i get null. I can accomplish this using DOM easily but i cant find anything at all about getting values out of it using SAX.
    Any help would be greatly appreciated.

  • How to define and populate value to a variable in a text file

    hi all,
    i have a text file on unix server, when i read it through open dataset, is it possible to populate dynamic value to a variable in the text file. and is it possible to define a variable at any place in the text file?
    after this the program will send the internal table for emailing.
    thanks.

    Hi, If this file on server is a email template you can put some tags / marks and you can change it after you read it with OPEN DATASET / READ...
    Sample:
    OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
    CHECK sy-subrc EQ 0.
    DO.
      READ DATASET p_file INTO lv_string.
      IF sy-subrc EQ 0.
        EXIT.
      ENDIF.
      REPLACE ALL OCCURENCES OF '((SYSTEM_ID))' WITH sy-sysid.
      APPEND input_file_tab.
    ENDDO.
    CLOSE DATASET p_file.
    on file there's a line with:
    This email was generated on server ((SYSTEM_ID))
    It will be translated to (sy-sysid = DEV):
    This email was generated on server DEV
    This is a "variable" like that you can use.

  • Select two diff fields and storing them in two variable in a same query ?

    Hello,
    i have a join query and i am selecting fields from different table(one field is the material number and second is bsad-wrbtr, on which i am doing the SUM). Now i cant store material number in a variable, cause i will be getting many material numbers(against 'vbeln') and sum( bsad-wrbtr ) will be stored collectively in a variable.
    Shud i be using an internal table to store both of them ? , cause i have to display all the material numbers retrieved . If yes, the how ? what will be the query like ?
    My current select/join query is,
      select  sum( bd~wrbtr ) into l_cramt
        from ( ( bsis as bs
                  inner join bsad as bd on bs~bukrs = bd~bukrs and
                                           bs~belnr = bd~augbl and
                                           bs~bldat = bd~augdt )
                  inner join vbrp as vb on vb~vbeln = bd~belnr )
        where bs~blart = 'DZ' and bs~hkont = p_hkont.
    Waiting for your replies, thank..
    Shehryar Dahar

    Hi,
    If you want to have a list of materials and sum for each of them try this:
    types: begin of t_list,
                matnr like vbrp-matnr,
                wrbtr like bsad-wrbtr,
             end of t_list.
    data: i_list type table of t_list.
      select  vbmatnr sum( bdwrbtr ) into table i_list
        from ( ( bsis as bs
                  inner join bsad as bd on bsbukrs = bdbukrs and
                                           bsbelnr = bdaugbl and
                                           bsbldat = bdaugdt )
                  inner join vbrp as vb on vbvbeln = bdbelnr )
        where bsblart = 'DZ' and bshkont = p_hkont
        group by vb~matnr.
    If you want to have a sum for a given material try this:
      select  vbmatnr sum( bdwrbtr ) into (v_matnr, v_wrbtr )
        from ( ( bsis as bs
                  inner join bsad as bd on bsbukrs = bdbukrs and
                                           bsbelnr = bdaugbl and
                                           bsbldat = bdaugdt )
                  inner join vbrp as vb on vbvbeln = bdbelnr )
        where bsblart = 'DZ' and bshkont = p_hkont
        and vb~matnr = p_matnr.

  • Parsing XML and HTML

    Is there any way to parse a XML file and covert it to a result set using SQL and PLSQL?

    Yes. Oracle SQL and PL/SQL can use the Oracle supplied XML Parser to create XML and to extract attributes and rows from XML.
    Refer to [url http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14259/toc.htm]Oracle® XML DB Developer's Guide.

  • Parsing XML and pulling out results rows only

    All,
    I need a bit of direction here, hopefully someone can help.
    Here is the situation..
    I have a Web Template that has the XML dataprovider only. Meaning, when I execute it, I get a blank screen because I am not using any other item. This is expected.
    The query works as designed and the XML data in the source of the web page is correct.
    Now, I want to be able to read (loop thru the XML data) and display the data in an HTML table for display to the end user. (Actually, I would like to only keep the "REsults Rows" from the XML data)
    Does anyone have any javascript/XSL/etc that takes the data from a web template, via the XML dataprovider function, and is able to process the data (XML data) and display as an HTML table on the same page?
    I am having a hard time finding any information on reading an XML dataset from the WAD and displaying it with any sort of success.
    I found lots of weblogs and threads about some similiar functionality, but it wasn't exactly what I was looking for.
    Here are some of the links I found..
    Re: XML Data Provider - Information
    I also found other threads from here, but none of them was exactly what I was looking for...(They were along the same lines as the first link!)
    I hope someone can help me out. Due points and my ever gratitude to whomever can help me on this one!
    Cheers!
    /smw

    1. Learn basic web service interfacing. The type of data is irrelevant.
    2. Learn how to parse XML.
    3. Learn how jdbc works.
    4. Learn how the protocol of your actual hosting company works.
    5. Put the above steps together to create your app.
    Steps 1, 2 and 3 are independent from each other.

  • How to parse xml and import to execel

    pls let me know how to parse XML file and import all data to execel sheet.

    Hi Mandya,
    This is outside of the normal use case for TestStand. It would be best to use a code module (developed in LabVIEW, C, or any other language) to accomlish this and then call it from a step in TestStand. You can find examples on ActiveX here:
    http://forums.ni.com/t5/NI-TestStand/Controlling-Excel-from-TestStand-with-Activex-Automation/td-p/1...
    I hope this helps.
    Frank L.
    Software Product Manager
    National Instruments

  • Parsing XML data stored as CLOB in DB and save attribute values in table

    Hello,
    I have a CLOB column in table that is holding XML data as follows,
    <banners>
    <banner-image id="0">
    <type>BANNER</type>
    <local-path>http.gif</local-path>
    <click-through-url>www</click-through-url>
    <make>Acura</make>
    </banner-image>
    <banner-image id="1">
    <type>BANNER</type>
    <local-path>http.gif</local-path>
    <click-through-url>gfrty</click-through-url>
    <make>BMW</make>
    </banner-image>
    </banners>
    Now I need to parse thru the above XML data and pull the attribute values to store in another table as follows,
    BANNER_IMAGE_ID | TYPE | LOCAL_PATH | CLICK_URL | MAKE
    0 | BANNER | http.gif | www | Acura
    1 | BANNER | http.gif | gfrty | BMW
    And XML data doesn't always end up with 2 rows in this table....some times it may be 3 or 4 as well. It is just that in this example it ended up with 2 rows.
    So, I would appreciate if someone can help me find a generic way of doing this,
    Thank you in advance,
    Madhu.

    This is not a reply.. sorry.
    I took have a similar problem only..
    can you pls help me
    XML structure.
    <PODetails>
    <POHeader>
    <CurrencyID>INR</CurrencyID>
    <ExchangeRate>1</ExchangeRate>
    <RefNo>0080000110</RefNo>
    <VendorID>1200</VendorID>
    <TransDate>2006-12-20</TransDate>
    <DocRelationshipId>PURCHASE</DocRelationshipId>
    <LocationID>0000102327</LocationID>
    </POHeader>
    <POItemDetails>
    <ItemID>ARSH1332</ItemID>
    <Size>L HS</Size>
    <Quality>Q1</Quality>
    <CustPO>rush order</CustPO>
    <UOM>PC</UOM>
    <Quantity>3.000</Quantity>
    <PriceValue>2509.5</PriceValue>
    <TaxAmount>0.00</TaxAmount>
    </POItemDetails>
    <POItemDetails>
    <ItemID>ARSH1332</ItemID>
    <Size>M HS</Size>
    <Quality>Q1</Quality>
    <CustPO>rush order</CustPO>
    <UOM>PC</UOM>
    <Quantity>2.000</Quantity>
    <PriceValue>1673</PriceValue>
    <TaxAmount>0.00</TaxAmount>
    </POItemDetails>
    <POItemDetails>
    <ItemID>ARSH1556</ItemID>
    <Size>39FS</Size>
    <Quality>Q1</Quality>
    <CustPO>rush order</CustPO>
    <UOM>PC</UOM>
    <Quantity>1.000</Quantity>
    <PriceValue>836.5</PriceValue>
    <TaxAmount>0.00</TaxAmount>
    </POItemDetails>
    </PODetails>
    The DB is ORACLE 9i
    This is stored in a XML table of type XMLTYPE.
    THIS I USED THE .extract function to get the values of the nodes.
    POHeader details are working fine. But when i get the POItemDetails i am getting 'ARSH1332ARSH1332ARSH1556' when i issue the command
    select a.extract('/PODetails/POItemDetails/ItemID/text()').getStringVal() ItemID
    FROM xmltable a
    WHERE a.existsnode('//POItemDetails/ItemID')=1
    Pls Help..
    Regds,
    Santhoshkumar.G.

  • About xml and null values in 10g

    Hi, I have an UCM GetFile webservice component wich receives 4 arguments, two of them are null values (rendition and extraPops), and the xml request generated by obpm is:
    <GetFileByName xmlns="http://www.stellent.com/GetFile/">
      <dDocName>V_123410</dDocName>
      <revisionSelectionMethod>latestReleased</revisionSelectionMethod>
      <rendition/>
      <extraProps/>
    </GetFileByName>The problem is: On UCM web service, an empty tag like <rendition/> is treated like a "empty string" value, instead of a null value, and then the response i get isn't the expected.
    What I want do to is change this behavior, and when I put null values in requests, the obpm should not write those tags. Is that possible?
    Should be like that:
    <GetFileByName xmlns="http://www.stellent.com/GetFile/">
      <dDocName>V_123410</dDocName>
      <revisionSelectionMethod>latestReleased</revisionSelectionMethod>
    </GetFileByName>Thanks!

    Hi,
    I have question regarding aggregates. It's possible to read data from BW aggregates? We have webi reports on a SAP BW multi cube and we would like to optimize retriving query.
    >> Because you are using the BW Query as the source all the items that you have done so far in terms of aggregation, indexing, ... is all valid and there are no specific steps required to leverage it with Web Intelligence. Make sure the aggregates are "correct" meansing that they do reflect what you are asking for in the Web Intelligence query panel
    How can we filter in webi query null (#) values. If we create condition that some variabe is diffrent from # we still get null (#) values in report.
    >> You should be able to create a variable. in case you tried that already could you be more specific ?
    thanks
    Ingo

  • Retrieving data from TCP/IP in xml and displaying values?

    Hey, I am using a program to retrieve data from a machine and outputting it in xml to the localhost.  On a seperate computer, I am trying to create a client application to read the xml data from that IP host and just output the important values instead of the whole script.  I am new to Labview and programming, has anyone written a program similar to what I am trying to accomplish?  I searched for it but couldn't quite find what I was looking for.  I really could use some help with trying to figure this out and appreciate any help or advice you could give me.   

    Where did you search? There are examples that ship with LabVIEW that show you how to do client-server applications using TCP/IP. Did you try those? You would need to add the parsing of the data you receive (i.e., the XML).

  • XML and Stored Procedures

    Hi,
    Is it possible to pass information to and from an Oracle stored procedure using a XML page? If so could you please point me to examples and/or white pages?
    Thanks!
    Tess

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Lillian Goodwin ([email protected]):
    Hi,
    Is it possible to pass information to and from an Oracle stored procedure using a XML page? If so could you please point me to examples and/or white pages?
    Thanks!
    Tess<HR></BLOCKQUOTE>
    Look at DB Prism, it works like Oracle Web Server but is based on servlet technology.
    With DB Prism you could make an stored procedure in PLSQL or Java and receive the XML values directly using the HTTP protocols.
    DB Prism is at Plenix Web Site
    This week DB Prism 1.1.0-dev will be ready for downloading including full compatibilty with OWS/OAS/IAS/Web DB toolkits.
    Best regards, Marcelo
    null

  • Is null and regular value in where ($variable)

    is there any polibility to create select depend on value in where ?
    select count(x) where y = $variablebut if variable is NULLit doesn't work cause must be IS NULL or IS NOT
    select count(x) where y is $variableIs there any posibility to make it working with null and regular variable?

    try:
    select count(x) from <yourtable> where nvl(y,<not_possible_value>) = nvl($variable,<not_possible_value>);where <not_possible_value> is a value that is not possible for column y.
    E.g. if y always is a positive number you could use the value -1.

  • How to parse XML and store the data in  tables using sql or plsql?

    I want to parse the xml
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xmlListWrapper>
        <size>2</size>
    <AppTypeID>10</AppTypeID>
    </xmlListWrapper>
    and store in a table
    |pk|apptypeid|
    1     10

    You can extract data from your XML along these lines...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      2  <xmlListWrapper>
      3    <size>2</size>
      4    <AppTypeID>10</AppTypeID>
      5    <AppTypeID>20</AppTypeID>
      6  </xmlListWrapper>') as xml from dual)
      7  --
      8  -- end of example data
      9  --
    10  select x.*
    11  from   t
    12        ,xmltable('/xmlListWrapper/AppTypeID'
    13                  passing t.xml
    14                  columns pk for ordinality
    15                         ,apptypeid number path '.'
    16*                ) x
    SQL> /
            PK  APPTYPEID
             1         10
             2         20
    SQL>
    Inserting it to a table is obviously achieved using an INSERT ... SELECT ... where the SELECT is extracting the data from the XML.

Maybe you are looking for

  • IPod not recognized by Windows

    Up until today, I have had relatively few problems syncing my 2g iPod touch. Earlier today, however, I had just ripped and CD and wanted to put it on my iPod, but got a repetative error message that the USB device isn't being recognized by windows. I

  • Subreport totals are not displayed correctly in Preview

    I'm using Crystal Reports 2008.  I have a subreport that sorts hiearchically.  It is placed in the Report Header of the main report.  Within the subreport, it has calculated totals for each hiearchy grouping.  When ran, those totals are incorrectly d

  • Cannot access backup files external drive - only unknown user can

    I've been in problems since a while with the _unknown user issue. I've read several discussions like the following: https://discussions.apple.com/thread/2290911?threadID=2290911 My problem is the following. I upgraded to snow leopard 10.6.7 and I did

  • Mountain Lion, Keynote & Autosave problems?

    I haven't upgraded to ML yet.  Just curious about user experiences with keynote and autosave.  When I upgraded to Lion, autosave would interrupt my typing with the "spinning wheel".  It was so disruptive to my workflow that I downgraded to the last v

  • Download internal table with column headings

    Hai Friends, How can i download the internal table with column headings?. i used to download and do some manual calculations to cross check the output.