Wierd Results when reading content between tags

Discussion in 'Java' started by Naren, May 11, 2004.

  1. Naren

    Naren Guest

    I have an XML like the one below.

    I am using SAX parsing and I need to get the information between the
    tags of the Email element. First i try to access the content and print
    it out and it gives me weird results.

    XML:
    /www.xmlspy.com) by AB(Co) --><!--Sample XML file generated by XML Spy
    v4.0.1 U (http://www.xmlspy.com)-->
    <RoomResRQ xmlns:commonelements="http://*.com/schema/CommonElements"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    Action="CreateNew">

    <RoomResSpecs>
    <RoomResSpec>
    <RoomResParty>
    <PartyMixInfo>
    <Email>

    </Email>
    </PartyMixInfo>
    </RoomResParty>
    </RoomResSpec>
    </RoomResSpecs>
    </RoomResRQ>


    The RESULT of running my parser on this is:

    /www.xmlspy.com) by AB(Co) --><!--Sample XML file generated by XML Spy
    v4.0.1 U (http://www.xmlspy.com)-->
    <RoomResRQ xmlns:commonelements="http://*.com/schema/CommonElements"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    Action="CreateNew">

    <RoomResSpecs>
    <RoomResSpec>
    <RoomResParty>
    <PartyMixInfo>
    <Email>




    I expect only the email address to be output, but everything else
    before the address is also printed.
    I appreciate if anyone can help.


    In startelement(), I have the following condition for email.
    if (localName.equals(Email)
    {
    readyForContent = true;
    }


    In the characters() method, I read the content only when the
    readyForContent flag is true. In the endElement() method, I first set
    the readyForContent flag to true.
    So, The content is read only when the flag is true and it happens only
    when the startElement is Email.

    public void characters(char[] ch, int start, int length)
    throws SAXException {

    if (readyForContent)
    {
    emailBuf = new StringBuffer();
    emailBuf.append(ch, start, length);
    System.out.println(emailBuf);

    }
    }


    public void endElement(String namespaceURI, String localName, String
    qName)
    throws SAXException {
    readyForContent = false;
    //clean the stack
    if (!tagStack.isEmpty()){
    tagStack.pop();
    }
    }
     
    Naren, May 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    PLS HELP: HTML email = wierd results

    VB Programmer, Aug 31, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    496
    Rutger Smit
    Aug 31, 2004
  2. VB Programmer

    Wierd results with Roles.IsUserInRole

    VB Programmer, Jan 15, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,844
    =?Utf-8?B?Sm9l?=
    Jan 15, 2006
  3. VB Programmer
    Replies:
    2
    Views:
    2,048
    VB Programmer
    Feb 10, 2006
  4. Naren
    Replies:
    0
    Views:
    585
    Naren
    May 11, 2004
  5. replacing tags between tags

    , Sep 18, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    129
    J├╝rgen Exner
    Sep 19, 2005
Loading...

Share This Page