Parsing XML in Java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Parsing XML in Java

Threaded View

  1. #1
    Join Date
    Apr 2004
    Location
    Cape Town, SA
    Posts
    8

    Exclamation Parsing XML in Java

    Hello Experts

    I got a slight problem. I have been trying to read in XML in Java using the javax.xml.parsers.DocumentBuilder and javax.xml.parsers.SAXParser classes but to no success . I new to using XML with java.

    What I need is to parse XML and be to retrieve the values or each tag.

    Below is a sample of the XML i need to pass:

    <?xml version="1.0" encoding="utf-8" ?>
    <ns:SISubscriberProfile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="http://www.openuri.org/">
    <ns:Type>1</ns:Type>
    <ns:Message>GET_CUSTOMER : SUCCESS</ns:Message>
    <ns:ErrorCode>0</ns:ErrorCode>
    <ns:Value>
    <ns:FirstName>Shaun</ns:FirstName>
    </ns:Value>
    <ns:IsLive xsi:type="xsd:boolean">true</ns:IsLive>
    </ns:SISubscriberProfile>

    If you take the line <ns:FirstName>Shaun</ns:FirstName>. I need to be able to pass a string (tag name, example "ns:FirstName") to a method and it should return the value of that tag as a string ("Shaun"). All the values i need to read are Strings.

    I use the basic code in the attachment (rename file to *.java).

    I can read the tagname but i can't get the value . What am i doing wrong? If possible could someone help me out by showing me the right code to read the value between the XML tag.

    Thank you.
    Attached Files Attached Files
    ___
    _/\/ \/\_
    (MC3)RaVeN

Similar Threads

  1. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 06:32 PM
  2. Replies: 1
    Last Post: 05-02-2002, 08:57 AM
  3. Try XML Junction
    By Tim in forum xml.announcements
    Replies: 0
    Last Post: 10-11-2001, 05:00 PM
  4. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 11:53 AM
  5. Replies: 1
    Last Post: 03-20-2001, 03:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center