logo       

RE: How to determine which Document to use: msg#00076

text.xml.xmlbeans.user

Subject: RE: How to determine which Document to use

Try this:
XmlObject doc = XmlObject.parse(...);
Then compare the XXXDocuments that you know about like this:
 
SchemaType t = doc.schemaType();
if (ADocument.type == t)
 ADocument a = (ADocument) doc;
else if (BDocument.type == t)
 BDocument b = (BDocument) doc;
 
In other words, documents are autotyped if a suitable type is found on the classpath and Schema Types are comparable using the '==' operator.
 
Radu
-----Original Message-----
From: Dogan Atay [mailto:DAtay@xxxxxxxxx]
Sent: Monday, January 10, 2005 6:13 AM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: How to determine which Document to use

Hi,

I just switched from JaxMe to XMLBeans and here is my first question already.

 

I have a schema with several global elements.  When compiled I end up with several XXXDocument classes.

 

I have written a client that has a method like this

 

public Object getObject(String xml)

{

}

 

What I want to do here is

1)       determine which XXXDocument class to use to parse this xml.

2)       parse the xml with that XXXDocument.factory and return the XXXDocument

 

I could not find a clean way to do this.

 

2 clumsy solutions come to my mind but I am wondering if any of you have a better solution.

 

In the fist solution I search the xml string for a tag named by my global element.

In the second solution I create a list of available Document.Factory classes and parse the xml using each of them until I receive no XmlException.

 

How else can I determine which Document.Factory to use?

 

Thanks,

 

Dogan Atay

 

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise