Eric,
this is also a question of what it is that you want to use to determine what is
the version of your document, in order to map the correct Schema. As Kevin
explains, XmlBeans can't use anything but the QName internally.
1) is probably not acceptable to you.
Here's my suggestion:
Build a list of SchemaTypeLoaders (using different classloaders or using the
SchemaTypeLoader APIs) ordered by your preference of Schema versions. Load the
document into memory and then validate it against each of the Schemas in the
list until it validates correctly. I don't know how efficient this would be,
but you see the idea.
Radu
-----Original Message-----
From: Kevin Krouse
Sent: Thursday, January 06, 2005 12:06 PM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: RE: Generated .jar files cause conflict
Yes, this is a known "problem" with how xmlbeans looks up schema information.
When xmlbeans builds the jar, all the schema information for elements goes into
the 'schema/elements' directory, the attribute information goes into
'schema/attributes', etc. Under those directories, the meta information filed
using the QName, for example 'schema/element/someNamespace/myElement.xsb'. In
your case you have two jars compiled from schemas with the same target
namespace and have elements of the same name. The result is the element .xsb
files in the second jar on the classpath is being masked by the .xsb files from
the first jar on the classpath.
The reason XmlBeans needs to use this lookup technique is clear when you think
about an instance that has an xsi:type attribute to change the element type,
eg. <myElement xsi:type="ns2:otherType" xmlns:ns2="otherNamespace"/>. You must
be able to lookup everything in the schema type system by QName to find what
"otherType" is.
There are only two solutions that I can see to your current situation: 1) is to
use a different namespace for each schema which, 2) is to put the conflicting
jars into two different classloaders.
Hope that helps!
--k
-----Original Message-----
From: Murphy, Eric [
mailto:erimurph@xxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, January 05, 2005 1:25 PM
To: 'user@xxxxxxxxxxxxxxxxxxx'
Subject: Generated .jar files cause conflict
XmlBeans -
We are implementing different versions of a specification which are based on
very similar schemas. Many of the tags in these schemas have the same names.
The specification authors have not used any namespaces.
We would like to use one servlet to evaluate the request then pass it to the
API that handles that version. We have compiled the XmlBeans classes into
different packages using a xsdconfig file and deploy the classes in separate
jars.
gdas090.jar and gdas091.jar are both in the class path.
Unfortunately when marshalling the main XML document we don't always get the
correct version returned from the Factory class. Example:
Org.nfis.gdas.v091.GdasCapabilitiesDocument doc =
GDASCapabilitiesDocument.Factory.parse(in);
The above line can throw a ClassCastException from the generated code from
at this line:
public static org.nfis.gdas.v091.GDASCapabilitiesDocument
parse(java.io.InputStream is)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.nfis.gdas.v091.GDASCapabilitiesDocument)
org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null );
}
Debugging I discovered the returned class was actually
org.nfis.gdas.v090.GDASCapabilitiesDocument (the incorrect version) which
resulted in the ClassCastException.
While we can put these versions in separate web containers to resolve this
problem we would rather not do this. Any thoughts about why this is
occurring?
Eric Murphy
Software Developer (NFIS)
erimurph@xxxxxxxxxxxxxxx
tel/tél: 250-363-6038
fax / télécopieur 250-363-6004
Natural Resources Canada
Pacific Forestry Centre
506 West Burnside Road
Victoria BC V8Z 1M5
Ressources naturelles Canada
Centre de foresterie du Pacifique
506 rue Burnside ouest
Victoria, Colombie-Britanique V8Z 1M5
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
Thread at a glance:
Previous Message by Date:
click to view message preview
RE: scomp Errors, Unuseful
I may be wrong, but isn't this caused by the fact that the default parser in V1
didn't support line numbers?
-----Original Message-----
From: Roland Pereira [mailto:PereiraR@xxxxxxxxxxx]
Sent: Thursday, January 06, 2005 6:57 AM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: RE: scomp Errors, Unuseful
Hello,
I resolved a similar issue last time. But I had to use JAXB and the
ant script within it to find the line numbers. I then went on to rectify the
.xsd file using jaxb. The corrected .xsd file was then used by XMLBeans
(scomp) to generate the jar file which I used to code.
Thanks
-----Original Message-----
From: P. Michael Hutchins [mailto:pmh0232@xxxxxxxxxx]
Sent: Wednesday, January 05, 2005 1:36 PM
To: user@xxxxxxxxxxxxxxxxxxx
Cc: Alex Kahn
Subject: scomp Errors, Unuseful
When I run scomp against an XSD file, I get any number of lines like:
> [].xsd:0: error: Must be less than or equal to previous maxInclusive
> [].xsd:0: error: Must be greater than or equal to previous
> minInclusive
That's not all that helpful, since there's 79 m{ax, in}Inclusive-s in the
xsd.
Is there a way to get actual line numbers of the offenders reported?
(the ":0:"s suggest so to me)
...and/or the offending text
Thanks,
-- M.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
Next Message by Date:
click to view message preview
RE : newDOMNode trouble
Yes : here is a file which cause me trouble :
<?xml version="1.0" encoding="ISO-8859-1"?>
<dummy xmlns="http://dufourrault"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:SchemaLocation="dummy.xsd">
<father>
<son>toto</son>
</father>
</dummy>
And the associated schema
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema targetNamespace="http://dufourrault"
xmlns:dr="http://dufourrault"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="dummy">
<xs:complexType>
<xs:sequence>
<xs:element name="father" type="dr:father"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="father">
<xs:sequence>
<xs:element name="son" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
TIA
Stéphane.
-----Message d'origine-----
De : Kevin Krouse [mailto:kkrouse@xxxxxxx]
Envoyé : jeudi 6 janvier 2005 20:14
À : user@xxxxxxxxxxxxxxxxxxx; Franco Lazzarino
Objet : RE: newDOMNode trouble
Can you can provide the schema and the xml instance that you are saving?
--k
-----Original Message-----
From: Franco Lazzarino [mailto:flazzarino@xxxxxxxxx]
Sent: Thursday, January 06, 2005 8:31 AM
To: user@xxxxxxxxxxxxxxxxxxx
Subject: Re: newDOMNode trouble
i don't know how much this helps but i've had similar null pointer exps
when working with DOM. they were all due to a Text node being null or
the text in it being null.
hope it helps.
Franco
On Thu, 06 Jan 2005 11:47:40 +0100, Stéphane Rault <ksbrault@xxxxxxxx>
wrote:
> Hello all again :)
>
> Do you need ore information to understand my problem or nobody can
> answer me ?
>
> TIA
>
> Stéphane.
>
> > Hello all !
> >
> > I'm quite new to xmlBeans and very impress by the work done.
> >
> > I tried to use the newDomNode() to get a DOM access to some point of
> > my document. So I use a getter to optain a XmlObject instance, I
> > print it with toString() and I obtain a xml-fragment. But when I
> > apply the
> > newDomNode() method on this xmlObject, i get this :
> >
> > Exception in thread "main" java.lang.NullPointerException
> > at
> > org.apache.xmlbeans.impl.store.Saver$DomSaver.emitContainer(Saver.ja
> > va:4514)
> >
> > at
> >
org.apache.xmlbeans.impl.store.Saver.processContainer(Saver.java:775)
> > at org.apache.xmlbeans.impl.store.Saver.process(Saver.java:518)
> > at
> >
org.apache.xmlbeans.impl.store.Saver$DomSaver.exportDom(Saver.java:4461)
> > at
org.apache.xmlbeans.impl.store.Cursor.newDomNode(Cursor.java:2954)
> > at
> > org.apache.xmlbeans.impl.values.XmlObjectBase.newDomNode(XmlObjectBa
> > se.java:154)
> >
> > at
> > org.apache.xmlbeans.impl.values.XmlObjectBase.newDomNode(XmlObjectBa
> > se.java:151)
> >
> > at test.TestXmlBeans.main(TestXmlBeans.java:47)
> >
> > Did I miss something ?
> >
> > Thanks in advance.
> > --
> > Stéphane.
> >
> > P.S. :
> >
> > My souce code fragment :
> >
> > Options prs =
> > doc.getCommunicationApplication().getGeneral().getOptions(); //
> > Options is the XmlObject instance
> >
> > System.out.println("prs = "+prs);
> > Element elt = (Element)
> > prs.newDomNode();
> >
> >
> >
> > --------------------------------------------------------------------
> > -
> > To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
> > For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
> For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
Previous Message by Thread:
click to view message preview
RE: Generated .jar files cause conflict
Yes, this is a known "problem" with how xmlbeans looks up schema information.
When xmlbeans builds the jar, all the schema information for elements goes into
the 'schema/elements' directory, the attribute information goes into
'schema/attributes', etc. Under those directories, the meta information filed
using the QName, for example 'schema/element/someNamespace/myElement.xsb'. In
your case you have two jars compiled from schemas with the same target
namespace and have elements of the same name. The result is the element .xsb
files in the second jar on the classpath is being masked by the .xsb files from
the first jar on the classpath.
The reason XmlBeans needs to use this lookup technique is clear when you think
about an instance that has an xsi:type attribute to change the element type,
eg. <myElement xsi:type="ns2:otherType" xmlns:ns2="otherNamespace"/>. You must
be able to lookup everything in the schema type system by QName to find what
"otherType" is.
There are only two solutions that I can see to your current situation: 1) is to
use a different namespace for each schema which, 2) is to put the conflicting
jars into two different classloaders.
Hope that helps!
--k
-----Original Message-----
From: Murphy, Eric [mailto:erimurph@xxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, January 05, 2005 1:25 PM
To: 'user@xxxxxxxxxxxxxxxxxxx'
Subject: Generated .jar files cause conflict
XmlBeans -
We are implementing different versions of a specification which are based on
very similar schemas. Many of the tags in these schemas have the same names.
The specification authors have not used any namespaces.
We would like to use one servlet to evaluate the request then pass it to the
API that handles that version. We have compiled the XmlBeans classes into
different packages using a xsdconfig file and deploy the classes in separate
jars.
gdas090.jar and gdas091.jar are both in the class path.
Unfortunately when marshalling the main XML document we don't always get the
correct version returned from the Factory class. Example:
Org.nfis.gdas.v091.GdasCapabilitiesDocument doc =
GDASCapabilitiesDocument.Factory.parse(in);
The above line can throw a ClassCastException from the generated code from
at this line:
public static org.nfis.gdas.v091.GDASCapabilitiesDocument
parse(java.io.InputStream is)
throws org.apache.xmlbeans.XmlException, java.io.IOException {
return (org.nfis.gdas.v091.GDASCapabilitiesDocument)
org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( is, type, null );
}
Debugging I discovered the returned class was actually
org.nfis.gdas.v090.GDASCapabilitiesDocument (the incorrect version) which
resulted in the ClassCastException.
While we can put these versions in separate web containers to resolve this
problem we would rather not do this. Any thoughts about why this is
occurring?
Eric Murphy
Software Developer (NFIS)
erimurph@xxxxxxxxxxxxxxx
tel/tél: 250-363-6038
fax / télécopieur 250-363-6004
Natural Resources Canada
Pacific Forestry Centre
506 West Burnside Road
Victoria BC V8Z 1M5
Ressources naturelles Canada
Centre de foresterie du Pacifique
506 rue Burnside ouest
Victoria, Colombie-Britanique V8Z 1M5
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xxxxxxxxxxxxxxxxxxx
For additional commands, e-mail: user-help@xxxxxxxxxxxxxxxxxxx
Next Message by Thread:
click to view message preview
invalid type error?
I am evaluating XmlBeans to replace some existing code in a project, and I
am getting an error when attempting to validate some xml. I have modified
the purchase order example to match what I am doing.
We are not using a namespace in our xml, but we still specify a schema to
validate against:
<?xml version="1.0" encoding="UTF-8"?>
<purchase-order
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="po.xsd">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>
The schema looks like:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="purchase-order">
<xs:complexType>
<xs:sequence>
<xs:element name="customer" type="customerType"/>
<xs:element name="date" type="xs:dateTime"/>
<xs:element name="line-item" type="line-itemType"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="shipper" type="shipperType"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="customerType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="line-itemType">
<xs:sequence>
<xs:element name="description" type="xs:string"/>
<xs:element name="per-unit-ounces" type="xs:decimal"/>
<xs:element name="price" type="xs:double"/>
<xs:element name="quantity" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="shipperType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="per-ounce-rate" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I am just using the default XmlObject.Factory to parse the po.xml file and
then calling the validate method on the resulting XmlObject. On the call to
validate, I get an "Invalid type" error:
Message: Invalid type.
Severity: 0
Line: -1
Location of invalid XML: <purchase-order
xsi:noNamespaceSchemaLocation="po.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer>
...
What does this mean? How can I fix/avoid it? XMLSpy validates both the
schema and xml file without errors.
The document parses without errors, and I can even perform a query against
it using XmlObject.selectPath().
If it helps, here is my code fragment:
File testFile = new File("c:/development/projects/sandbox/po.xml");
System.out.println("File exists: " + testFile.exists() + "; " +
testFile.getAbsolutePath());
XmlObject document = null;
XmlOptions opts = new XmlOptions();
ArrayList errorList = new ArrayList();
opts.setErrorListener(errorList);
try {
document = XmlObject.Factory.parse(testFile, opts);
}
catch (XmlException e) {
System.out.println("exception: " + e.getMessage());
return;
}
catch (IOException e) {
System.out.println("exception: " + e.getMessage());
return;
}
if (errorList.size() != 0) {
System.out.println("parse errors:");
for (int i = 0; i < errorList.size(); i++) {
XmlError error = (XmlError)errorList.get(i);
System.out.println("\n" + "Message: " + error.getMessage());
System.out.println("Severity: " + error.getSeverity());
System.out.println("Line: " + error.getLine());
System.out.println("Location of invalid XML: " +
error.getCursorLocation().xmlText() + "\n");
}
errorList.clear();
}
if (!document.validate(opts)) {
System.out.println("validation errors:");
for (int i = 0; i < errorList.size(); i++) {
XmlError error = (XmlError)errorList.get(i);
System.out.println("\n" + "Message: " + error.getMessage());
System.out.println("Severity: " + error.getSeverity());
System.out.println("Line: " + error.getLine());
System.out.println("Location of invalid XML: " +
error.getCursorLocation().xmlText() + "\n");
}
}
String queryExpression =
"/purchase-order/customer[name='Gladys Kravitz']";
XmlObject[] productObj = document.selectPath(queryExpression);
System.out.println(productObj[0]);
Thanks for any understanding you can share here,
-Mark