xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: Wrapping xml-fragment into AnyDocument looses runtime type information
Date Fri, 19 Mar 2004 07:04:46 GMT
Why are you averse to using <xml-fragment>?  Is it because it does not
have a namespace?  

My understanding of xsi:type is that you can't use it to declare the
type of an element.  The name of the document element defines that
instance type.  So, your any wrapper does not have a specific type, and
xsi:type will not give it one.  Xsi:type is usually used to specify a
derived type of the type inferred from the document element.

In XmlBeans, when we load a fragment, I look to see if there is an
xsi:type at the top, and infer the type from that.  However, when I do
this, I am removing the document element (because it is just a wrapper
for a fragment of otherwise mal-formed XML).

The reason that you are loosing the xsi:type when you call the set
method is that the type of the any is not a base type for the right hand
side.  Thus, I remove the xsi:type.  Ultimately, the set is simply
copying the contents of the right hand side to the new contents of the
any element, sans the xsi:type.

If you want to save the type of your instance, you may want to wrap it
with an element which identifies this type with respect the schema which
defines the type.

- Eric

-----Original Message-----
From: Alex Paransky [mailto:apara@standardset.com] 
Sent: Thursday, March 18, 2004 7:44 PM
To: xmlbeans-user@xml.apache.org
Subject: Wrapping xml-fragment into AnyDocument looses runtime type
information

I posted this message on the Bea newsgroup, but I think most of the 
action is here anyway...

I would like to store a fragment of xml in a database. However, to stay 
XML compatible, I don't want to have <xml-fragment> tags. To avoid this,

I attempt to "wrap" the xml-fragment inside of an AnyDocument using the 
following code:

private static AnyDocument wrap(final XmlObject o) {
  final AnyDocument anyDocument = AnyDocument.Factory.newInstance();
  final AnyDocument.Any any = anyDocument.addNewAny();
  any.set(o);
  return anyDocument;
}

The problem, is that somehow my runtime type is getting lost after the 
wrapping occurs.

Here is how the data looks BEFORE wrap (o.save()):

<?xml version="1.0" encoding="UTF-8"?>
<xml-fragment
  xsi:type="loc:AddTermRequestT"
  xmlns:loc="http://www.overture.com/service/common/local" 
<http://www.overture.com/service/common/local>
  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
<http://schemas.xmlsoap.org/soap/envelope/>
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
<http://schemas.xmlsoap.org/soap/encoding/>
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
<http://www.w3.org/2001/XMLSchema>
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
<http://www.w3.org/2001/XMLSchema-instance>
  xmlns:dis="http://www.overture.com/service/display" 
<http://www.overture.com/service/display>
 > <http://www.overture.com/service/display>
  <loc:accountId>1123223ZZZ</loc:accountId>
  <loc:term>dog</loc:term>
  <loc:price>0.55</loc:price>
</xml-fragment>

Note that in the above XML the runtime type is set as: 
xsi:type="loc:AddTermRequestT

Here is how the data looks after I attempt to wrap it with AnyDocument:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:any
  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
<http://schemas.xmlsoap.org/soap/envelope/>
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
<http://www.w3.org/2001/XMLSchema-instance>
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
<http://schemas.xmlsoap.org/soap/encoding/>
  xmlns:dis="http://www.overture.com/service/display" 
<http://www.overture.com/service/display>
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
<http://www.w3.org/2001/XMLSchema>
  xmlns:loc="http://www.overture.com/service/common/local" 
<http://www.overture.com/service/common/local>
  > <http://www.overture.com/service/common/local>
  <loc:accountId>1123223ZZZ</loc:accountId>
  <loc:term>dog</loc:term>
  <loc:price>0.55</loc:price>
</xsd:any>

The runtime type (xsi:type="loc:AddTermRequestT) is gone and it's not 
clear how to parse the new XML.

Am I doing something wrong? Why does the runtime type go away? Is this 
the correct way to "warp" some fragment with a valid document.

Again, the intent here is to store something to the database that a 
different tool can understand later.

Thanks.

-- 
-AP_
http://www.myprofiles.com/member/profile/apara_personal
http://www.myprofiles.com/member/profile/apara_business



- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message