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 21:17:21 GMT
I don't think this use of "any" works this way.  The only reason
<xml-fragment> works, is that after a document is loaded, I look at the
root of the document for certain signatures which I can use to bind the
document to a type.  XmlBean's loading mechanism is capable of stripping
the <xml-fragment> tag out and looking for xsi:type and associating that
type with the new document.
 
Without XmlBeans, you can only count on documents whose document
elements correspond to a global element in a schema you have.
 
- Eric
 
-----Original Message-----
From: Alexander Paransky [mailto:Alexander.Paransky@Overture.com] 
Sent: Friday, March 19, 2004 1:03 AM
To: xmlbeans-user@xml.apache.org; xmlbeans-user@xml.apache.org;
apara@standardset.com
Subject: RE: Wrapping xml-fragment into AnyDocument looses runtime type
information
 
The reason I am averse to using <xml-fragment> is that I don't believe
it makes for a valid XMLSchema document since it is not defined.  I am
storing XML data in a database and other tools might want to look at
this data.  I would like the data I am trying to store to be a "valid"
XMLSchema document so other tools have no problems understanding the
data.
 
Your last statement "... you may want to wrap it with an element which
identifies this type with respect to the schema which defines the
type..." makes sense to me.  However, I am looking for a "generic" way
to do this.  We are starting with XML in general, so I am not even sure
if there is a way to do this.
 
Our thinking was since everything is derived from an Any, an Any is at
the "base" of all the types.  In this case:
 
...
<xml-fragment xsi:type="loc:AddTermRequestT"...
 
is equivalent to 
 
...
<xsd:any xsi:type="loc:AddTermRequestT" ...
 
Wouldn't it be?
 
Technically, I could use one of the XmlOptions().setSave.... features to
change the "xml-fragment" to "<xsd:any"  but I am not sure if the
resultant XML is valid according to the XMLSchema.
 
Thanks.
-AP_
	-----Original Message----- 
	From: Eric Vasilik [mailto:ericvas@bea.com] 
	Sent: Thu 3/18/2004 11:04 PM 
	To: xmlbeans-user@xml.apache.org; apara@standardset.com 
	Cc: 
	Subject: RE: Wrapping xml-fragment into AnyDocument looses
runtime type information
	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