You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Ranjith Kodikara <ra...@dmsswt.com> on 2005/01/06 04:30:59 UTC

Dropping tag content upto a special character when parsing XML

Hi,
I am parsing an XML file with SAX with java. My java class extends DefaultHandler and I m overrriding startElement(), characters() and endElement() methods. Special characters  like ',< are replaced with appropriate strings like &#39; and &gt etc in my xml document. I replace the apostrophe( ' ) symbol with &#39; for it to be <book>Rober Nox&#39;s Stories</book> and in Internet explorer it displays the tag content accurately. 
The problem is when a string in xml file contains a ' symbol, it truncates the content of the string up to ' symbol. 
For example if there is an element like <book>Rober Nox's Stories</book>, the parser outputs 's Stories instead of Rober Nox's Stories. 

Is there any way to overcome this problem? Any help is greatly appreciated. 

Regards,
Ranjith


                        
                  
                        Ranjith Kodikara
                        Systems Engineer  DMS Software Technologies
                        165, Dharmapala Mawatha,
                        Colombo 00700  
                        ranjith@dmsswt.com  tel: 
                              tel2: +94-11-2673973
                              +94-11-2696648  
                       
                 
            
     
            
     

Re: Dropping tag content upto a special character when parsing XML

Posted by Bob Foster <bo...@objfac.com>.
Accumulate characters in a StringBuffer until you get an endElement.

Bob Foster

Ranjith Kodikara wrote:
> Hi,
> 
> Thanks for the reply. Is there any easy way of handling this?  or If you
> know a place where I can get some examples, please let me know.
> 
> Thanks,
> Ranjith
> 
> ----- Original Message ----- 
> From: "Michael Glavassevich" <mr...@ca.ibm.com>
> To: <xe...@xml.apache.org>
> Sent: Thursday, January 06, 2005 9:39 AM
> Subject: Re: Dropping tag content upto a special character when parsing XML
> 
> 
> 
>>characters() may be called multiple times for contiguous text. It's one of
>>the finer details of SAX. This gets reported so often it has its own FAQ
>>[1].
>>
>>[1] http://xml.apache.org/xerces2-j/faq-sax.html#faq-2
>>
>>"Ranjith Kodikara" <ra...@dmsswt.com> wrote on 01/05/2005 10:30:59 PM:
>>
>>
>>>Hi,
>>>I am parsing an XML file with SAX with java. My java class extends
>>>DefaultHandler and I m overrriding startElement(), characters() and
>>>endElement() methods. Special characters  like ',< are replaced with
>>>appropriate strings like &#39; and &gt etc in my xml document. I
>>>replace the apostrophe( ' ) symbol with &#39; for it to be <book>Rober
>>
>>Nox
>>
>>>&#39;s Stories</book> and in Internet explorer it displays the tag
>>>content accurately.
>>>The problem is when a string in xml file contains a ' symbol, it
>>>truncates the content of the string up to ' symbol.
>>>For example if there is an element like <book>Rober Nox's Stories</book>
>>>, the parser outputs 's Stories instead of Rober Nox's Stories.
>>>
>>>Is there any way to overcome this problem? Any help is greatly
>>
>>appreciated.
>>
>>>Regards,
>>>Ranjith
>>>
>>>
>>>[image removed]
>>>
>>>Ranjith Kodikara
>>>Systems Engineer
>>>
>>>DMS Software Technologies
>>>165, Dharmapala Mawatha,
>>>Colombo 00700
>>>
>>>ranjith@dmsswt.com
>>>
>>>tel:
>>>tel2:
>>>
>>>+94-11-2673973
>>>+94-11-2696648
>>
>>Michael Glavassevich
>>XML Parser Development
>>IBM Toronto Lab
>>E-mail: mrglavas@ca.ibm.com
>>E-mail: mrglavas@apache.org
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Dropping tag content upto a special character when parsing XML

Posted by Ranjith Kodikara <ra...@dmsswt.com>.
Hi,

Thanks for the reply. Is there any easy way of handling this?  or If you
know a place where I can get some examples, please let me know.

Thanks,
Ranjith

----- Original Message ----- 
From: "Michael Glavassevich" <mr...@ca.ibm.com>
To: <xe...@xml.apache.org>
Sent: Thursday, January 06, 2005 9:39 AM
Subject: Re: Dropping tag content upto a special character when parsing XML


> characters() may be called multiple times for contiguous text. It's one of
> the finer details of SAX. This gets reported so often it has its own FAQ
> [1].
>
> [1] http://xml.apache.org/xerces2-j/faq-sax.html#faq-2
>
> "Ranjith Kodikara" <ra...@dmsswt.com> wrote on 01/05/2005 10:30:59 PM:
>
> > Hi,
> > I am parsing an XML file with SAX with java. My java class extends
> > DefaultHandler and I m overrriding startElement(), characters() and
> > endElement() methods. Special characters  like ',< are replaced with
> > appropriate strings like &#39; and &gt etc in my xml document. I
> > replace the apostrophe( ' ) symbol with &#39; for it to be <book>Rober
> Nox
> > &#39;s Stories</book> and in Internet explorer it displays the tag
> > content accurately.
> > The problem is when a string in xml file contains a ' symbol, it
> > truncates the content of the string up to ' symbol.
> > For example if there is an element like <book>Rober Nox's Stories</book>
> > , the parser outputs 's Stories instead of Rober Nox's Stories.
> >
> > Is there any way to overcome this problem? Any help is greatly
> appreciated.
> >
> > Regards,
> > Ranjith
> >
> >
> > [image removed]
> >
> > Ranjith Kodikara
> > Systems Engineer
> >
> > DMS Software Technologies
> > 165, Dharmapala Mawatha,
> > Colombo 00700
> >
> > ranjith@dmsswt.com
> >
> > tel:
> > tel2:
> >
> > +94-11-2673973
> > +94-11-2696648
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Dropping tag content upto a special character when parsing XML

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
characters() may be called multiple times for contiguous text. It's one of 
the finer details of SAX. This gets reported so often it has its own FAQ 
[1].

[1] http://xml.apache.org/xerces2-j/faq-sax.html#faq-2

"Ranjith Kodikara" <ra...@dmsswt.com> wrote on 01/05/2005 10:30:59 PM:

> Hi,
> I am parsing an XML file with SAX with java. My java class extends 
> DefaultHandler and I m overrriding startElement(), characters() and 
> endElement() methods. Special characters  like ',< are replaced with
> appropriate strings like &#39; and &gt etc in my xml document. I 
> replace the apostrophe( ' ) symbol with &#39; for it to be <book>Rober 
Nox
> &#39;s Stories</book> and in Internet explorer it displays the tag 
> content accurately. 
> The problem is when a string in xml file contains a ' symbol, it 
> truncates the content of the string up to ' symbol. 
> For example if there is an element like <book>Rober Nox's Stories</book>
> , the parser outputs 's Stories instead of Rober Nox's Stories. 
> 
> Is there any way to overcome this problem? Any help is greatly 
appreciated. 
> 
> Regards,
> Ranjith
> 
> 
> [image removed] 
> 
> Ranjith Kodikara
> Systems Engineer 
> 
> DMS Software Technologies
> 165, Dharmapala Mawatha,
> Colombo 00700 
> 
> ranjith@dmsswt.com 
> 
> tel: 
> tel2:
> 
> +94-11-2673973
> +94-11-2696648 

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org