[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-user
Subject: Re: Parsing an XML fragment
From: "Pascal Maugeri" <pascal.maugeri () gmail ! com>
Date: 2008-05-02 18:35:11
Message-ID: 990aed650805021135v4d45c0a3n1a6303c10135a41b () mail ! gmail ! com
[Download RAW message or body]
:-O What a mistake on my part ! Sorry for that ...
Everything works pretty well now. Thank you Radu for your great help.
Regards
Pascal
On Fri, May 2, 2008 at 2:07 AM, Radu Preotiuc-Pietro <radup@bea.com> wrote:
> Hi Pascal,
>
> You have to decide whether "uri" is an element or an attribute. In your
> original example it was an attribute, but in the Schema you send it shows
> it's an element. If it is element, obviously, your XML would have to look
> like (it has nothing to do with fragments):
>
> String xml = "<ns:element xmlns:ns=\"
> http://www.example.org/docelement\ <http://www.example.org/docelement%5C>
> "><ns:uri>www.apache.org</ns:uri></ns:element>";
> Radu
>
> ------------------------------
> *From:* Pascal Maugeri [mailto:pascal.maugeri@gmail.com]
> *Sent:* Thursday, May 01, 2008 1:54 PM
>
> *To:* user@xmlbeans.apache.org
> *Subject:* Re: Parsing an XML fragment
>
> Hi Radu
>
> There is some progress here...
>
> I did modified the xml as you recommended and the following code:
>
> String xml = "<ns:element uri=\"www.apache.org\" xmlns:ns=\"
> http://www.example.org/docelement\ <http://www.example.org/docelement%5C>
> "/>";
> XmlOptions xmlOptions = new
> XmlOptions().setDocumentType(DocDocument.Doc.type);
> DocDocument.Doc doc = (DocDocument.Doc)
> XmlObject.Factory.parse(xml, xmlOptions);
> System.out.println(doc.toString());
> System.out.println(doc.getElement().toString());
> System.out.println(doc.getElement().getUri());
>
> outputs:
>
> <ns:element uri="www.apache.org" xmlns:ns="
> http://www.example.org/docelement"/>
> <xml-fragment uri="www.apache.org" xmlns:ns="
> http://www.example.org/docelement"/>
> null
>
> As you can see the doc.getElement.getUri() still returns null :-(
>
> I've played around with the schema, for instance I switched
> elementFormDefault to "unqualified":
>
> String xml = "<element uri=\"www.apache.org\"/>";
> XmlOptions xmlOptions = new
> XmlOptions().setDocumentType(DocDocument.Doc.type);
> DocDocument.Doc doc = (DocDocument.Doc)
> XmlObject.Factory.parse(xml, xmlOptions);
> System.out.println(doc.toString());
> System.out.println(doc.getElement().toString());
> System.out.println(doc.getElement().getUri());
>
> outputs:
>
> <element uri="www.apache.org"/>
> <xml-fragment uri="www.apache.org"/>
> null
>
> I get the same results (doc.getElement().getUri() is null).
>
> I also tried with attributeFormDefault="unqualified" with no success
> neither:
>
> String xml = "<ns:element ns:uri=\"www.apache.org\" xmlns:ns=\"
> http://www.example.org/docelement\ <http://www.example.org/docelement%5C>
> "/>";
> XmlOptions xmlOptions = new
> XmlOptions().setDocumentType(DocDocument.Doc.type);
> DocDocument.Doc doc = (DocDocument.Doc)
> XmlObject.Factory.parse(xml, xmlOptions);
> System.out.println(doc.toString());
> System.out.println(doc.getElement().toString());
> System.out.println(doc.getElement().getUri());
>
> Do you have any idea why I can't access the element attribute ?
>
> Thanks
> Pascal
>
> On Thu, May 1, 2008 at 1:09 AM, Radu Preotiuc-Pietro <radup@bea.com>
> wrote:
>
> > Yep, in your Schema you have elementFormDefault="qualified". So this
> > means your doc fragment has to look like:
> >
> > String xml = "<ns:element uri=\"www.apache.org\" xmlns:ns=
> > \"http://www.example.org/docelement\<http://www.example.org/docelement%5C>
> > "/>";
> >
> > Radu
> >
> > On Wed, 2008-04-30 at 15:07 +0200, Pascal Maugeri wrote:
> > > Hi Radu
> > >
> > > Sorry again to comment on this issue but I do not find the same
> > > results as yours.
> > >
> > > with the following source code:
> > >
> > > String xml = "<element uri=\"www.apache.org\"/>";
> > > XmlOptions xmlOptions = new
> > > XmlOptions().setDocumentType(DocDocument.Doc.type);
> > > DocDocument.Doc doc = (DocDocument.Doc)
> > > XmlObject.Factory.parse(xml, xmlOptions);
> > > System.out.println(doc.toString());
> > > System.out.println(doc.getElement().toString());
> > >
> > > The first sysout prints the correct result:
> > >
> > > <element uri="www.apache.org"/>
> > >
> > > The last sysout throws a NullPointerException because doc.getElement()
> > > returns null
> > >
> > > java.lang.NullPointerException
> > > at
> > > xmlbeans.ParsingXmlFragment.<init>(ParsingXmlFragment.java:17)
> > > at xmlbeans.ParsingXmlFragment.main(ParsingXmlFragment.java:22)
> > >
> > > I've attached to this email the beans jar I've generated and the piece
> > > of code I tested. If you want to dedicate more time to this issue it
> > > may be interesting to execute it in your environment. Please confirm
> > > me that you do not get the exception.
> > >
> > > Regards,
> > > Pascal
> > >
> > >
> > >
> > > On Tue, Apr 29, 2008 at 2:27 AM, Radu Preotiuc-Pietro <radup@bea.com>
> > > wrote:
> > > Actually, I have made some experiments myself and you may have
> > > success
> > > with something like:
> > >
> > > DocDocument.Doc doc = (DocDocument.Doc)
> > > XmlObject.Factory.parse(new
> > > File("test.xml"), new
> > > XmlOptions().setDocumentType(DocDocument.Doc.type));
> > >
> > > to parse from the <element> level.
> > >
> > > Let me know if this works for you,
> > > Radu
> > >
> > >
> > > > -----Original Message-----
> > > > From: Jim the Standing Bear [mailto:standingbear@gmail.com]
> > > > Sent: Monday, April 28, 2008 8:38 AM
> > > > To: user@xmlbeans.apache.org
> > > > Subject: Re: Parsing an XML fragment
> > > >
> > > > I ran into the same problem and toyed around it over the
> > > weekend.
> > > > what I found out was that it helps if you parse it from "a
> > > level up".
> > > >
> > > > So in your case, you would have to parse it from the
> > > Document
> > > > level, since that is the only thing above "Element" nodes.
> > > >
> > > > In other words, doing
> > > > Doc.Factory.parse(xml).getDoc().getElement().getUri() is the
> > > > way to go. However, you said you needed to parse from
> > > > Element level - is there any constraints that force you to
> > > > parse from Element level?
> > > >
> > > > HTH
> > > >
> > > > Jim
> > > >
> > > >
> > > >
> > > > On Mon, Apr 28, 2008 at 6:17 AM, Pascal Maugeri
> > > > <pascal.maugeri@gmail.com> wrote:
> > > > > Radu
> > > > >
> > > > > You're right in the example below the <element> is not a
> > > > global schema type.
> > > > >
> > > > > So what should I do if a server (XCAP server) sends me
> > > this
> > > > XML fragment:
> > > > >
> > > > >
> > > > > <element uri="www.apache.org"/>
> > > > >
> > > > > and I want to parse it having the xml beans set from the
> > > > corresponding
> > > > > schema ?
> > > > >
> > > > > Is there a way to do that ?
> > > > >
> > > > > Regards,
> > > > > Pascal
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On Sat, Apr 19, 2008 at 3:35 AM, Radu Preotiuc-Pietro
> > > > <radup@bea.com> wrote:
> > > > >
> > > > > > I'd have to see the Schema to be able to figure out the
> > > name of
> > > > > > elements and types and what the exact code should look
> > > > like. I think
> > > > > > that your problem might be that <element> is not a
> > > global Schema
> > > > > > type and so auto-typing doesn't work if at the root
> > > level
> > > > (in other
> > > > > > words, Schema doesn't allow <element> to be a top-level
> > > element).
> > > > > >
> > > > > > But even then, you should not have to parse and save to
> > > > String only
> > > > > > to parse again.
> > > > > >
> > > > > > Radu
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Tue, 2008-04-08 at 06:49 -0700, Pascal Maugeri wrote:
> > > > > > > Hi
> > > > > > >
> > > > > > > I would like to have a clarification about the parsing
> > > of a XML
> > > > > > > fragment.
> > > > > > >
> > > > > > > For instance, having the following XML document, I
> > > want
> > > > to obtain
> > > > > > > the "uri" attribute value:
> > > > > > >
> > > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > > <doc>
> > > > > > > <element uri="www.apache.org"/>
> > > > > > > </doc>
> > > > > > >
> > > > > > > with
> > > > > > >
> > > Doc.Factory.parse(xml).getDoc().getElement().getUri()
> > > > > > > it returns the attribute value.
> > > > > > >
> > > > > > > but with
> > > > > > > Element.Factory.parse("<element
> > > > > > > uri=\"www.apache.org\"/>").getUri()
> > > > > > > it returns null, also a call to
> > > Element.Factory.parse("<element
> > > > > > > uri=
> > > > > > > \"www.apache.org\"/>").toString() returns the XML
> > > content.
> > > > > > >
> > > > > > > As I do need to parse XML fragment such as this
> > > > "element", I have
> > > > > > > found the following workaround:
> > > > > > > a) I get the String representation of the Element (eg.
> > > > > > > Element.Factory.parse(...).toString() ),
> > > > > > > b) I insert the result of (a) into a container
> > > <doc>...</doc>
> > > > > > > c) then I parse the result of (b) with the
> > > > Doc.Factory.parse( (b)
> > > > > > > ).getDoc().getElement().getUri() and it does work.
> > > > > > > ... also I'm not very proud of myself :-)
> > > > > > >
> > > > > > > Could you explain why I can't access the attributes of
> > > a XML
> > > > > > > fragment I parsed ?
> > > > > > >
> > > > > > > I there a better/cleaner workaround than the one
> > > above ?
> > > > > > >
> > > > > > > Thanks in advance for your help
> > > > > > > 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
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > --------------------------------------
> > > > 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
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>
> 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.
>
[Attachment #3 (text/html)]
> -O What a mistake on my part ! Sorry for that ...<br><br>Everything works pretty \
> well now. Thank you Radu for your great \
> help.<br><br>Regards<br>Pascal<br><br><br><br><div class="gmail_quote">On Fri, May \
> 2, 2008 at 2:07 AM, Radu Preotiuc-Pietro <<a \
> href="mailto:radup@bea.com">radup@bea.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial" size="2">Hi \
Pascal,</font></span></div> <div dir="ltr" align="left"><span><font color="#0000ff" \
face="Arial" size="2"></font></span> </div> <div dir="ltr" \
align="left"><span><font color="#0000ff" face="Arial" size="2">You have to decide \
whether "uri" is an element or an attribute. In your original example it \
was an attribute, but in the Schema you send it shows it's an element. If it is \
element, obviously, your XML would have to look like (it has nothing to do with \
fragments):</font></span></div> <div dir="ltr" align="left"><span><font \
color="#0000ff" face="Arial" size="2"></font></span> </div> <div dir="ltr" \
align="left"><span><font color="#0000ff" face="Arial" \
size="2"> String xml = \
"<ns:element xmlns:ns=\"<a href="http://www.example.org/docelement%5C" \
target="_blank">http://www.example.org/docelement\</a>"><ns:uri><a \
href="http://www.apache.org" \
target="_blank">www.apache.org</a></ns:uri></ns:element>";<br> \
</font></span></div> <div dir="ltr" align="left"><span><font color="#0000ff" \
face="Arial" size="2">Radu</font></span></div><br> <blockquote style="border-left: \
2px solid rgb(0, 0, 255); padding-left: 5px; margin-left: 5px; margin-right: 0px;"> \
<div dir="ltr" align="left" lang="en-us"> <hr>
<font face="Tahoma" size="2"><div class="Ih2E3d"><b>From:</b> Pascal Maugeri
[mailto:<a href="mailto:pascal.maugeri@gmail.com" \
target="_blank">pascal.maugeri@gmail.com</a>] <br></div><b>Sent:</b> Thursday, May \
01, 2008 1:54 PM<div><div></div><div class="Wj3C7c"><br><b>To:</b> <a \
href="mailto:user@xmlbeans.apache.org" \
target="_blank">user@xmlbeans.apache.org</a><br><b>Subject:</b> Re: Parsing an XML \
fragment<br></div></div></font><br></div><div><div></div><div class="Wj3C7c"> \
<div></div>Hi Radu<br><br>There is some progress here...<br><br>I did modified the \
xml as you recommended and the following code:<br><br> \
String xml = "<ns:element uri=\"www.apache.org\" \
xmlns:ns=\"<a href="http://www.example.org/docelement%5C" \
target="_blank">http://www.example.org/docelement\</a>"/>";<br> \
XmlOptions xmlOptions = new
XmlOptions().setDocumentType(DocDocument.Doc.type);<br>
DocDocument.Doc doc = (DocDocument.Doc)
XmlObject.Factory.parse(xml, xmlOptions);<br>
System.out.println(doc.toString()); <br>
System.out.println(doc.getElement().toString());<br>
System.out.println(doc.getElement().getUri());<br><br>outputs:<br><br>
<div style="margin-left: 40px;"><ns:element uri="<a \
href="http://www.apache.org" target="_blank">www.apache.org</a>" \
xmlns:ns="<a href="http://www.example.org/docelement" \
target="_blank">http://www.example.org/docelement</a>"/><br> <xml-fragment \
uri="<a href="http://www.apache.org" target="_blank">www.apache.org</a>" \
xmlns:ns="<a href="http://www.example.org/docelement" \
target="_blank">http://www.example.org/docelement</a>"/><br>null<br> \
</div><br>As you can see the doc.getElement.getUri() still returns null \
:-(<br><br>I've played around with the schema, for instance I switched \
elementFormDefault to "unqualified":<br><br> \
String xml = "<element \
uri=\"www.apache.org\"/>";<br> \
XmlOptions xmlOptions = new \
XmlOptions().setDocumentType(DocDocument.Doc.type);<br> \
DocDocument.Doc doc = (DocDocument.Doc) \
XmlObject.Factory.parse(xml, xmlOptions);<br> \
System.out.println(doc.toString());<br>
System.out.println(doc.getElement().toString());<br>
System.out.println(doc.getElement().getUri());<br><br>outputs:<br><br>
<div style="margin-left: 40px;"><element uri="<a \
href="http://www.apache.org" \
target="_blank">www.apache.org</a>"/><br><xml-fragment uri="<a \
href="http://www.apache.org" \
target="_blank">www.apache.org</a>"/><br>null<br></div><br>I get the same \
results (doc.getElement().getUri() is null).<br><br>I also tried with \
attributeFormDefault="unqualified" with no success \
neither:<br><br> String xml = \
"<ns:element ns:uri=\"www.apache.org\" xmlns:ns=\"<a \
href="http://www.example.org/docelement%5C" \
target="_blank">http://www.example.org/docelement\</a>"/>";<br> \
XmlOptions xmlOptions = new
XmlOptions().setDocumentType(DocDocument.Doc.type);<br>
DocDocument.Doc doc = (DocDocument.Doc)
XmlObject.Factory.parse(xml, xmlOptions);<br>
System.out.println(doc.toString());<br>
System.out.println(doc.getElement().toString());<br>
System.out.println(doc.getElement().getUri());<br><br>Do
you have any idea why I can't access the element attribute
?<br><br>Thanks<br>Pascal<br><br>
<div class="gmail_quote">On Thu, May 1, 2008 at 1:09 AM, Radu Preotiuc-Pietro
<<a href="mailto:radup@bea.com" target="_blank">radup@bea.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Yep, in your Schema you have \
elementFormDefault="qualified". So this<br>means your doc fragment has to \
look like:<br><br>String xml = "<ns:element \
uri=\"www.apache.org\" xmlns:ns=<br>\"<a \
href="http://www.example.org/docelement%5C" \
target="_blank">http://www.example.org/docelement\</a>"/>";<br><font \
color="#888888"><br>Radu<br></font> <div>
<div></div>
<div><br>On Wed, 2008-04-30 at 15:07 +0200, Pascal Maugeri
wrote:<br>> Hi Radu<br>><br>> Sorry again to comment on this issue
but I do not find the same<br>> results as yours.<br>><br>> with
the following source code:<br>><br>>
String xml = "<element \
uri=\"www.apache.org\"/>";<br>> \
XmlOptions xmlOptions = new<br>> \
XmlOptions().setDocumentType(DocDocument.Doc.type);<br>> \
DocDocument.Doc doc = (DocDocument.Doc)<br>> XmlObject.Factory.parse(xml, \
xmlOptions);<br>> \
System.out.println(doc.toString());<br>> \
System.out.println(doc.getElement().toString());<br>><br>> The first sysout \
prints the correct result:<br>><br>> <element uri="<a \
href="http://www.apache.org" \
target="_blank">www.apache.org</a>"/><br>><br>> The last sysout \
throws a NullPointerException because doc.getElement()<br>> returns \
null<br>><br>> java.lang.NullPointerException<br>> \
at<br>> xmlbeans.ParsingXmlFragment.<init>(ParsingXmlFragment.java:17)<br>> \
at
xmlbeans.ParsingXmlFragment.main(ParsingXmlFragment.java:22)<br>><br>>
I've attached to this email the beans jar I've generated and the
piece<br>> of code I tested. If you want to dedicate more time to this
issue it<br>> may be interesting to execute it in your environment.
Please confirm<br>> me that you do not get the exception.<br>><br>>
Regards,<br>> Pascal<br>><br>><br>><br>> On Tue, Apr 29, 2008
at 2:27 AM, Radu Preotiuc-Pietro <<a href="mailto:radup@bea.com" \
target="_blank">radup@bea.com</a>><br>> wrote:<br>> \
Actually, I have made some experiments myself and you may have<br>> \
success<br>> with \
something like:<br>><br>> DocDocument.Doc doc = \
(DocDocument.Doc)<br>> \
XmlObject.Factory.parse(new<br>> \
File("test.xml"), new<br>> \
XmlOptions().setDocumentType(DocDocument.Doc.type));<br>><br>> \
to parse from the <element> level.<br>><br>> \
Let me know if this works for you,<br>> \
Radu<br>><br>><br>> > \
-----Original Message-----<br>> > From: Jim the \
Standing Bear [mailto:<a href="mailto:standingbear@gmail.com" \
target="_blank">standingbear@gmail.com</a>]<br>> \
> Sent: Monday, April 28, 2008 8:38 AM<br>> > \
To: <a href="mailto:user@xmlbeans.apache.org" \
target="_blank">user@xmlbeans.apache.org</a><br>> \
> Subject: Re: Parsing an XML fragment<br>> \
><br>> > I ran into the same problem and toyed \
around it over the<br>> weekend.<br>> \
> what I found out was that it helps if you parse it from
"a<br>> level up".<br>> \
><br>> > So in your case,
you would have to parse it from the<br>>
Document<br>> > level, since that is the
only thing above "Element" nodes.<br>>
><br>> > In other words, doing<br>>
>
Doc.Factory.parse(xml).getDoc().getElement().getUri() is the<br>>
> way to go. However, you said you needed to
parse from<br>> > Element level - is there
any constraints that force you to<br>> >
parse from Element level?<br>> ><br>>
> HTH<br>>
><br>> > Jim<br>>
><br>> ><br>>
><br>> > On Mon,
Apr 28, 2008 at 6:17 AM, Pascal Maugeri<br>>
> <<a href="mailto:pascal.maugeri@gmail.com" \
target="_blank">pascal.maugeri@gmail.com</a>> wrote:<br>> \
> > Radu<br>> > ><br>> \
> > You're right in the example below the \
<element> is not a<br>> > global schema \
type.<br>> > ><br>> \
> > So what should I do if a server (XCAP server) sends me<br>> \
this<br>> > XML
fragment:<br>> > ><br>>
> ><br>> > >
<element uri="<a href="http://www.apache.org" \
target="_blank">www.apache.org</a>"/><br>> \
> ><br>> > > and I want to parse it \
having the xml beans set from the<br>> > \
corresponding<br>> > > schema ?<br>> \
> ><br>> > > Is \
there a way to do that ?<br>> > ><br>> \
> > Regards,<br>> \
> > Pascal<br>> > ><br>> \
> ><br>> > \
><br>> > ><br>> \
> > On Sat, Apr 19, 2008 at 3:35 AM, Radu Preotiuc-Pietro<br>> \
> <<a href="mailto:radup@bea.com" \
target="_blank">radup@bea.com</a>> wrote:<br>> \
> ><br>> > > > I'd have to see \
the Schema to be able to figure out the<br>> name \
of<br>> > > > elements and types and what \
the exact code should look<br>> > like. I \
think<br>> > > > that your problem might be \
that <element> is not a<br>> global
Schema<br>> > > > type and so
auto-typing doesn't work if at the root<br>>
level<br>> > (in other<br>>
> > > words, Schema doesn't allow
<element> to be a top-level<br>>
element).<br>> > > ><br>>
> > > But even then, you should not have to
parse and save to<br>> > String
only<br>> > > > to parse
again.<br>> > > ><br>>
> > > Radu<br>>
> > ><br>> > > ><br>>
> > ><br>>
> > ><br>> > > > On
Tue, 2008-04-08 at 06:49 -0700, Pascal Maugeri wrote:<br>>
> > > > Hi<br>>
> > > ><br>> > > > >
I would like to have a clarification about the parsing<br>>
of a XML<br>> > > >
> fragment.<br>> > > >
><br>> > > > > For instance,
having the following XML document, I<br>>
want<br>> > to obtain<br>>
> > > > the "uri" attribute \
value:<br>> > > > ><br>> \
> > > > <?xml version="1.0"
encoding="UTF-8"?><br>> > > \
> > <doc><br>> > > >
> <element uri="<a href="http://www.apache.org" \
target="_blank">www.apache.org</a>"/><br>> \
> > > > </doc><br>> > \
> > ><br>> > > > > with<br>> \
> > > ><br>> \
Doc.Factory.parse(xml).getDoc().getElement().getUri()<br>>
> > > > it returns the attribute value.<br>>
> > > ><br>>
> > > > but with<br>> >
> > > Element.Factory.parse("<element<br>>
> > > >
uri=\"www.apache.org\"/>").getUri()<br>> \
> > > > it returns null, also a call to<br>> \
Element.Factory.parse("<element<br>>
> > > > uri=<br>>
> > > > \"www.apache.org\"/>").toString() returns \
the XML<br>> content.<br>>
> > > ><br>> >
> > > As I do need to parse XML fragment such as this<br>>
> "element", I have<br>> \
> > > > found the following workaround:<br>>
> > > > a) I get the String
representation of the Element (eg.<br>> >
> > > Element.Factory.parse(...).toString() ),<br>>
> > > > b) I insert the result of (a) into
a container<br>>
<doc>...</doc><br>> > >
> > c) then I parse the result of (b) with the<br>>
> Doc.Factory.parse( (b)<br>>
> > > > ).getDoc().getElement().getUri() and it does
work.<br>> > > > > ... also I'm
not very proud of myself :-)<br>> > >
> ><br>> > > > > Could you
explain why I can't access the attributes of<br>>
a XML<br>> > > > >
fragment I parsed ?<br>> > > >
><br>> > > > > I there a
better/cleaner workaround than the one<br>>
above ?<br>> > > > ><br>>
> > > > Thanks in advance for your
help<br>> > > > > Pascal<br>>
> > ><br>>
> > > Notice: This email message, together with
any<br>> attachments, may<br>>
> > > contain<br>>
> > information of BEA Systems, Inc.,
its subsidiaries<br>> and<br>>
> > affiliated entities, that may be
confidential,<br>> proprietary,<br>>
> > copyrighted and/or legally
privileged, and is intended<br>> > solely
for the<br>> > > use of the individual
or entity named in this message. If<br>> >
you are not<br>> > > the intended
recipient, and have received this message in<br>>
error,<br>> > > please
immediately return this by email and then delete<br>>
it.<br>> > > ><br>>
> > ><br>>
><br>>
--------------------------------------------------------------------<br>>
> > > - To unsubscribe, e-mail:<br>>
<a href="mailto:user-unsubscribe@xmlbeans.apache.org" \
target="_blank">user-unsubscribe@xmlbeans.apache.org</a><br>> \
> > > For additional commands, e-mail:<br>> \
<a href="mailto:user-help@xmlbeans.apache.org" \
target="_blank">user-help@xmlbeans.apache.org</a><br>> \
> > ><br>> > > ><br>> \
> ><br>> > \
><br>> ><br>> \
><br>> ><br>> \
> --<br>> > \
--------------------------------------<br>> > \
Standing Bear Has Spoken<br>> > \
--------------------------------------<br>> \
><br>> ><br>>
---------------------------------------------------------------------<br>>
> To unsubscribe, e-mail: <a \
href="mailto:user-unsubscribe@xmlbeans.apache.org" \
target="_blank">user-unsubscribe@xmlbeans.apache.org</a><br>> \
> For additional commands, e-mail:<br>> \
<a href="mailto:user-help@xmlbeans.apache.org" \
target="_blank">user-help@xmlbeans.apache.org</a><br>> \
><br>> ><br>><br>> \
Notice: This email message, together with any \
attachments,<br>> may contain information of \
BEA Systems, Inc., its<br>> \
subsidiaries and affiliated entities, that may be<br>> \
confidential, proprietary, copyrighted \
and/or legally<br>> privileged, and is \
intended solely for the use of the<br>> individual \
or entity named in this message. If you are not the<br>>
intended recipient, and have received this message in
error,<br>> please immediately return this by
email and then delete it.<br>><br>>
---------------------------------------------------------------------<br>>
To unsubscribe, e-mail: <a \
href="mailto:user-unsubscribe@xmlbeans.apache.org" \
target="_blank">user-unsubscribe@xmlbeans.apache.org</a><br>> \
For additional commands, e-mail: <a \
href="mailto:user-help@xmlbeans.apache.org" \
target="_blank">user-help@xmlbeans.apache.org</a><br>><br>><br>><br>> \
---------------------------------------------------------------------<br>>
To unsubscribe, e-mail: <a href="mailto:user-unsubscribe@xmlbeans.apache.org" \
target="_blank">user-unsubscribe@xmlbeans.apache.org</a><br>> For additional \
commands, e-mail: <a href="mailto:user-help@xmlbeans.apache.org" \
target="_blank">user-help@xmlbeans.apache.org</a><br><br>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.<br><br>---------------------------------------------------------------------<br>To \
unsubscribe, e-mail: <a href="mailto:user-unsubscribe@xmlbeans.apache.org" \
target="_blank">user-unsubscribe@xmlbeans.apache.org</a><br>For additional \
commands, e-mail: <a href="mailto:user-help@xmlbeans.apache.org" \
target="_blank">user-help@xmlbeans.apache.org</a><br><br></div></div></blockquote></div><br></div></div></blockquote></div><div><div></div><div \
class="Wj3C7c">
<br>
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.</div> </div></blockquote></div><br>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic