You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Jim the Standing Bear <st...@gmail.com> on 2008/04/27 02:30:10 UTC
another xml fragment parse question
Hello,
Not so long ago someone asked a question about parsing xml fragment.
I am also running into some issues with parsing XML fragments and
would like to get some clarifications from you experts.
The xmlBeans I am working with is structured like this:
AResponseDocument --> AResponseType --> BDataType --> (choice of
either) CType[0..*] (or) DType[0..*]
In other words (if my illustrations above wasn't clear enough), I am
getting a response document back from some web service call, and the
response contains a BDataType object, which in turn contains an array
of CType objects or an array of DType objects.
Currently, only CType is used.
The problem I ran into is that sometimes, I have to parse an input
stream of characters into a BDataType, and a typical stream looks like
the following:
<typ1:bData xmlns:typ1="...">
<typ1:c>
... some stuff here ...
</typ1:c>
</typ1:bData>
However, when I tried to do this
BDataType bdt = BDataType.Factory.parse(inputStream);
it did not parse correctly, because
System.out.println(bdt.getCList().size());
gives me 0, and I was expecting 1 since there is always a "c" element
present in the data stream
Is this because the data stream I am getting is missing the
<xml-fragment> tags??
I printed bdt.xmlText() from an actual BDataType object, and noticed
the xmlText is surrounded by <xml-fragment> tags. When I tried to
parse that xml text, it actually worked.
One obvious solution for me right now, would be to grab the
inputStream and store it into a string, surround it by the
<xml-fragment> tags, and then call BDataType.Factory.parse(string)...
but I would prefer to avoid converting the input stream to a string.
A place online suggests that one should always parse from "one level
up", but when I tried this:
AResponseType art = AResponseType.Factory.parse(inputStream)
I get a null pointer exception when I say
art.getBDataType();
So is there any other way??? Thanks!
-- Jim
--
--------------------------------------
Standing Bear Has Spoken
--------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: another xml fragment parse question
Posted by Jim the Standing Bear <st...@gmail.com>.
Actually it worked. At first I thought it did not work and returned
null, but that was only because hours of looking at xml fragments with
elements with similar names made me temporarily dyslexic.
On Mon, Apr 28, 2008 at 8:28 PM, Radu Preotiuc-Pietro <ra...@bea.com> wrote:
> The place that suggested you use AResponseType to parse was correct,
> because that is the type that contains the <bData> element. Always, the
> declared content of the type that is used to parse an XML document has
> to match the actual elements being parsed.
>
> The way <xml-fragment> works is that it allows you to parse content that
> would otherwise be invalid XML. You can parse fragments with multiple
> root elements or even attributes by themselves. By wrapping everything
> with an <xml-fragment> element, the XML parser won't reject it as
> not-well-formed XML and then XMLBeans will know to remove the extra
> element before processing.
>
> So I will be interested to know in more detail why the recommendation to
> use AResposeType did not work for you, maybe a Schema snippet, a code
> snippet etc. (There could be things like namespace mismatches etc which
> can't be diagnosed without having the details available)
>
> Radu
>
>
>
> > -----Original Message-----
> > From: Jim the Standing Bear [mailto:standingbear@gmail.com]
> > Sent: Saturday, April 26, 2008 5:30 PM
> > To: user@xmlbeans.apache.org
> > Subject: another xml fragment parse question
> >
> > Hello,
> >
> > Not so long ago someone asked a question about parsing xml fragment.
> > I am also running into some issues with parsing XML fragments
> > and would like to get some clarifications from you experts.
> >
> > The xmlBeans I am working with is structured like this:
> >
> > AResponseDocument --> AResponseType --> BDataType --> (choice of
> > either) CType[0..*] (or) DType[0..*]
> >
> > In other words (if my illustrations above wasn't clear
> > enough), I am getting a response document back from some web
> > service call, and the response contains a BDataType object,
> > which in turn contains an array of CType objects or an array
> > of DType objects.
> >
> > Currently, only CType is used.
> >
> > The problem I ran into is that sometimes, I have to parse an
> > input stream of characters into a BDataType, and a typical
> > stream looks like the following:
> > <typ1:bData xmlns:typ1="...">
> > <typ1:c>
> > ... some stuff here ...
> > </typ1:c>
> > </typ1:bData>
> >
> > However, when I tried to do this
> >
> > BDataType bdt = BDataType.Factory.parse(inputStream);
> >
> > it did not parse correctly, because
> >
> > System.out.println(bdt.getCList().size());
> >
> > gives me 0, and I was expecting 1 since there is always a "c"
> > element present in the data stream
> >
> > Is this because the data stream I am getting is missing the
> > <xml-fragment> tags??
> >
> > I printed bdt.xmlText() from an actual BDataType object, and
> > noticed the xmlText is surrounded by <xml-fragment> tags.
> > When I tried to parse that xml text, it actually worked.
> >
> > One obvious solution for me right now, would be to grab the
> > inputStream and store it into a string, surround it by the
> > <xml-fragment> tags, and then call BDataType.Factory.parse(string)...
> > but I would prefer to avoid converting the input stream to a string.
> > A place online suggests that one should always parse from
> > "one level up", but when I tried this:
> >
> > AResponseType art = AResponseType.Factory.parse(inputStream)
> >
> > I get a null pointer exception when I say
> >
> > art.getBDataType();
> >
> >
> > So is there any other way??? Thanks!
> >
> > -- Jim
> >
> >
> >
> >
> >
> > --
> > --------------------------------------
> > Standing Bear Has Spoken
> > --------------------------------------
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> > For additional commands, e-mail: user-help@xmlbeans.apache.org
> >
> >
>
> 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
>
>
--
--------------------------------------
Standing Bear Has Spoken
--------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
RE: another xml fragment parse question
Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
The place that suggested you use AResponseType to parse was correct,
because that is the type that contains the <bData> element. Always, the
declared content of the type that is used to parse an XML document has
to match the actual elements being parsed.
The way <xml-fragment> works is that it allows you to parse content that
would otherwise be invalid XML. You can parse fragments with multiple
root elements or even attributes by themselves. By wrapping everything
with an <xml-fragment> element, the XML parser won't reject it as
not-well-formed XML and then XMLBeans will know to remove the extra
element before processing.
So I will be interested to know in more detail why the recommendation to
use AResposeType did not work for you, maybe a Schema snippet, a code
snippet etc. (There could be things like namespace mismatches etc which
can't be diagnosed without having the details available)
Radu
> -----Original Message-----
> From: Jim the Standing Bear [mailto:standingbear@gmail.com]
> Sent: Saturday, April 26, 2008 5:30 PM
> To: user@xmlbeans.apache.org
> Subject: another xml fragment parse question
>
> Hello,
>
> Not so long ago someone asked a question about parsing xml fragment.
> I am also running into some issues with parsing XML fragments
> and would like to get some clarifications from you experts.
>
> The xmlBeans I am working with is structured like this:
>
> AResponseDocument --> AResponseType --> BDataType --> (choice of
> either) CType[0..*] (or) DType[0..*]
>
> In other words (if my illustrations above wasn't clear
> enough), I am getting a response document back from some web
> service call, and the response contains a BDataType object,
> which in turn contains an array of CType objects or an array
> of DType objects.
>
> Currently, only CType is used.
>
> The problem I ran into is that sometimes, I have to parse an
> input stream of characters into a BDataType, and a typical
> stream looks like the following:
> <typ1:bData xmlns:typ1="...">
> <typ1:c>
> ... some stuff here ...
> </typ1:c>
> </typ1:bData>
>
> However, when I tried to do this
>
> BDataType bdt = BDataType.Factory.parse(inputStream);
>
> it did not parse correctly, because
>
> System.out.println(bdt.getCList().size());
>
> gives me 0, and I was expecting 1 since there is always a "c"
> element present in the data stream
>
> Is this because the data stream I am getting is missing the
> <xml-fragment> tags??
>
> I printed bdt.xmlText() from an actual BDataType object, and
> noticed the xmlText is surrounded by <xml-fragment> tags.
> When I tried to parse that xml text, it actually worked.
>
> One obvious solution for me right now, would be to grab the
> inputStream and store it into a string, surround it by the
> <xml-fragment> tags, and then call BDataType.Factory.parse(string)...
> but I would prefer to avoid converting the input stream to a string.
> A place online suggests that one should always parse from
> "one level up", but when I tried this:
>
> AResponseType art = AResponseType.Factory.parse(inputStream)
>
> I get a null pointer exception when I say
>
> art.getBDataType();
>
>
> So is there any other way??? Thanks!
>
> -- Jim
>
>
>
>
>
> --
> --------------------------------------
> Standing Bear Has Spoken
> --------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>
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