You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Pascal Maugeri <pa...@gmail.com> on 2008/04/03 21:09:08 UTC

Basic question about parsing with XmlCursor

Hi

I do not manage to obtain the same results described in the XmlCursor
javadoc (
http://xmlbeans.apache.org/docs/2.0.0/reference/org/apache/xmlbeans/XmlCursor.html)
when analyzing the sample XML file.

According to the javadoc I should get:

 <sample x='y'>
     <value>foo</value>
 </sample>

STARTDOC
START (sample)
ATTR (x='y')
TEXT ("\n ")
START (value)
TEXT ("foo")
END (value)
TEXT ("\n")
END (sample)
ENDDOC


But with my source code:

            XmlObject xmlObj = XmlObject.Factory.parse("<sample
x='y'><value>foo</value></sample>");
            XmlCursor curs = xmlObj.newCursor();

            while (!curs.isEnd()) {
                XmlCursor.TokenType tokenType = curs.currentTokenType();
                System.out.println(tokenType.toString());
                curs.toNextToken();
            }


I only get:

STARTDOC
START
ATTR
START
TEXT

How should I modify my code to obtain the other tokens of the document (eg.
END of sample, value, document, etc.) ?

Thanks in advance for your help
Regards,
Pascal

Re: Basic question about parsing with XmlCursor

Posted by Pascal Maugeri <pa...@gmail.com>.
Thank you very much Radu !!
This was the last place I was looking for my mistake.
-pascal


On Thu, Apr 3, 2008 at 10:44 PM, Radu Preotiuc-Pietro <ra...@bea.com> wrote:

> After a cursor-y look, I would say you need to replace
>
>  while(!curs.isEnd())
>
> with
>
>  while(!curs.isEnddoc())
>
> Radu
>
> On Thu, 2008-04-03 at 21:09 +0200, Pascal Maugeri wrote:
> > Hi
> >
> > I do not manage to obtain the same results described in the XmlCursor
> > javadoc
> > (
> http://xmlbeans.apache.org/docs/2.0.0/reference/org/apache/xmlbeans/XmlCursor.html)
> when analyzing the sample XML file.
> >
> > According to the javadoc I should get:
> >  <sample x='y'>
> >      <value>foo</value>
> >  </sample>
> > STARTDOC
> > START (sample)
> > ATTR (x='y')
> > TEXT ("\n ")
> > START (value)
> > TEXT ("foo")
> > END (value)
> > TEXT ("\n")
> > END (sample)
> > ENDDOC
> >
> >
> > But with my source code:
> >
> >             XmlObject xmlObj = XmlObject.Factory.parse("<sample
> > x='y'><value>foo</value></sample>");
> >             XmlCursor curs = xmlObj.newCursor();
> >
> >             while (!curs.isEnd()) {
> >                 XmlCursor.TokenType tokenType =
> > curs.currentTokenType();
> >                 System.out.println(tokenType.toString());
> >                 curs.toNextToken();
> >             }
> >
> >
> > I only get:
> >
> > STARTDOC
> > START
> > ATTR
> > START
> > TEXT
> >
> > How should I modify my code to obtain the other tokens of the document
> > (eg. END of sample, value, document, etc.) ?
> >
> > Thanks in advance for your help
> > Regards,
> > Pascal
> >
>
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual or
> entity named in this message. If you are not the intended recipient, and
> have received this message in error, please immediately return this by email
> and then delete it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

Re: Basic question about parsing with XmlCursor

Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
After a cursor-y look, I would say you need to replace

  while(!curs.isEnd())

with

  while(!curs.isEnddoc())

Radu

On Thu, 2008-04-03 at 21:09 +0200, Pascal Maugeri wrote:
> Hi
> 
> I do not manage to obtain the same results described in the XmlCursor
> javadoc
> (http://xmlbeans.apache.org/docs/2.0.0/reference/org/apache/xmlbeans/XmlCursor.html) when analyzing the sample XML file. 
> 
> According to the javadoc I should get: 
>  <sample x='y'>
>      <value>foo</value>
>  </sample>
> STARTDOC 
> START (sample) 
> ATTR (x='y') 
> TEXT ("\n ") 
> START (value) 
> TEXT ("foo") 
> END (value) 
> TEXT ("\n") 
> END (sample)
> ENDDOC 
> 
> 
> But with my source code:
> 
>             XmlObject xmlObj = XmlObject.Factory.parse("<sample
> x='y'><value>foo</value></sample>");
>             XmlCursor curs = xmlObj.newCursor();
>             
>             while (!curs.isEnd()) {
>                 XmlCursor.TokenType tokenType =
> curs.currentTokenType();
>                 System.out.println(tokenType.toString());
>                 curs.toNextToken();
>             }
> 
> 
> I only get:
> 
> STARTDOC
> START
> ATTR
> START
> TEXT
> 
> How should I modify my code to obtain the other tokens of the document
> (eg. END of sample, value, document, etc.) ?
> 
> Thanks in advance for your help
> Regards,
> Pascal
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

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