[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-dev
Subject: RE: Type and instance
From: "Springer, Ian P." <ian.springer () hp ! com>
Date: 2005-04-27 20:55:58
Message-ID: 6D6463F31027B14FB3B1FB094F2C74470775D9D1 () tayexc17 ! americas ! cpqcorp ! net
[Download RAW message or body]
Haneef,
There are two ways to parse in an unknown element that has a known type,
which result in slightly different behavior:
METHOD 1:
XmlObject.Factory.parse( MY_EPR, new XmlOptions().setDocumentType(
org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument.ty
pe ) );
METHOD 2:
XmlObject.Factory.parse( MY_EPR, new
XmlOptions().setLoadReplaceDocumentElement( new QName(
"http://schemas.xmlsoap.org/ws/2003/03/addressing", "EndpointReference"
)) );
Both will return a
org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument,
assuming you have this class in your classpath. The difference is that
when you toString() the returned document XmlBean, method 1 will print
the original name (e.g. wsf:MyEndpointReference), but method 2 will
print the name that you specified when you called parse() (i.e.
wsa:EndpointReference).
The below test program will demonstrate this behavior.
Ian
-----
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import
org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument;
import javax.xml.namespace.QName;
public class Tester
{
static final String MY_EPR = "<MyEndpointReference
xmlns:wsa='http://schemas.xmlsoap.org/ws/2003/03/addressing'><wsa:Addres
s>http://localhost:8080/muse/services/blackberry</wsa:Address></MyEndpoi
ntReference>";
public static void main( String[] args ) throws Exception
{
EndpointReferenceDocument epr = (EndpointReferenceDocument)
XmlObject.Factory.parse( MY_EPR, new XmlOptions().setDocumentType(
EndpointReferenceDocument.type ) );
System.out.println( epr );
EndpointReferenceDocument epr2 = (EndpointReferenceDocument)
XmlObject.Factory.parse( MY_EPR, new
XmlOptions().setLoadReplaceDocumentElement( new QName(
"http://schemas.xmlsoap.org/ws/2003/03/addressing", "EndpointReference"
)) );
System.out.println( epr2 );
}
}
| -----Original Message-----
| From: Ali, Haneef
| Sent: Wednesday, April 27, 2005 2:44 PM
| To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
| Subject: Type and instance
|
| Hi,
|
| Consider the following schema ( this is from ws-addressing)
|
| <compleType name="EndpointRefernceType">
| ....
| </complexType>
|
| <element name="EndpointReference" type="EndpointReferenceType"
| />
|
| A) I do have compiled xmlbeans2.0 stubs for the above schema.
| B) Assume user creates the following xml fragment
|
| <?xml version="1.0" ?>
| <MyEndpointReference xsi:type="EndpointRefernceType">
| ....
| </MyEndpointReference>
|
|
| Is it possible for me to parse this fragment? I don't have
| stubs for "MyEndpointReference". I do have stubs for its
| type. Using it I'm able to parse , but I'm not able to get
| any value, since all the values are null.
|
| Questions:
| 1) Any idea how can I parse and get the contents? I
| don't want to use XmlCurosr, as I will loose the type information.
| 2) What is the use of EndPointReferneceType.Factory.parse(),
| Only if parsed using the corresponding document, class I''m
| getting proper values.
| 3) Is there an alternate way to handle type/instance
| with xmlbeans. I don't want to create stubs ( I can't create
| stubs) for instance, but can create stubs for type.
|
|
| Regards,
| Haneef
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
| For additional commands, e-mail: dev-help@xmlbeans.apache.org
|
|
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic