Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Wierd Results when reading content between tags

Reply
Thread Tools

Wierd Results when reading content between tags

 
 
Naren
Guest
Posts: n/a
 
      05-11-2004
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>
http://www.velocityreviews.com/forums/(E-Mail Removed)
</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>
(E-Mail Removed)



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();
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
content is not allowed between the opening and closing tags steve@thepinksofa.com ASP .Net 2 04-15-2007 12:39 AM
Error: Content is not allowed between the opening and closing tags for element Allan Ebdrup ASP .Net 0 01-26-2006 08:45 AM
Error: Content is not allowed between the opening and closing tags for element Allan Ebdrup ASP .Net Web Controls 0 01-20-2006 09:01 AM
replacing tags between tags beartiger@gmail.com Perl Misc 9 09-19-2005 02:32 AM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM



Advertisments