O
orb_at_cts_dot_com
Folks,
can you suggest a way around this feature of XmlBeans?
I have have two XML Schema, furniture_table.xsd and
html_table.xsd (see below) that both define a root
element "table".
Scomp was used to make two JARS, one for unmarshalling
html_table XML instance docs, and another for unmarshalling
furniture_table XML instance docs.
When I try to unmarshal my HTML table, the furniture table
Types get in the way. The HTML JAR must be in the
java execution CLASSPATH *before* the furniture JAR,
otherwise I get a message
org.apache.xmlbeans.XmlException: XML object is not of type D=table
I assume this is because when XmlBeans looks up what class is bound
to <table> it finds html.HTMLTableDocument if HTML_TABLE.jar
is first and furniture.FURNTableDocument if
FURNITURE_TABLE.jar is first.
Any suggestions on how to avoid this CLASSPATH dependency?
Thanks for reading
Max
APPENDIX 1. My source code...
public void test()
{
try
{
System.out.println("Test is beginning...");
HTMLTableDocument htmlTable =
HTMLTableDocument.Factory.parse(new
File("C:/Temp/XmlBeansBug/html_table.xml"));
System.out.println("Parsed OK.");
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
System.out.println("Test is finished!");
}
APPENDIX 2. The result of running my code
Test is beginning...
org.apache.xmlbeans.XmlException: XML object is not of type D=table
at
org.apache.xmlbeans.impl.store.Root.autoTypedDocument(Root.java:436)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1038)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1022)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:322)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:233)
at html.HTMLTableDocument$Factory.parse(HTMLTableDocument.java:208)
at TestXmlBeans.test(TestXmlBeans.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Test is finished!
APPENDIX 3. My XSDs
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="table">
<xs:annotation>
<xs:documentation>HTML table</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="row" minOccurs="1" maxOccurs="256" >
<xs:complexType>
<xs:sequence>
<xs:element name="cell" type="xs:string" minOccurs="1"
maxOccurs="256"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="table">
<xs:annotation>
<xs:documentation>this is an HTML table</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="leg" minOccurs="1" maxOccurs="4"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
APPENDIX 4. XML instance doc
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Temp\XmlBeansBug\html_table.xsd">
<row>
<cell>Kaczynski </cell>
<cell>Nichols</cell>
</row>
<row>
<cell>Moussaoui<html_table.xsdconfig/cell>
<cell>Yousef</cell>
</row>
</table>
APPENDIX 5. My xsdconfig files...
<?xml version="1.0" encoding="UTF-8"?>
<xb:config
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
<xb:namespace uri="##any">
<xbackage>html</xbackage>
<xbrefix>HTML</xbrefix>
</xb:namespace>
</xb:config>
<?xml version="1.0" encoding="UTF-8"?>
<xb:config
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
<xb:namespace uri="##any">
<xbackage>furniture</xbackage>
<xbrefix>FURN</xbrefix>
</xb:namespace>
</xb:config>
APPENDIX 6 My BAT file
SET SCOMP_JARS=%XMLBEANS_HOME%\lib\jsr173_1.0_api.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\xmlpublic.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\xbean.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\resolver.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\xbean_xpath.jar
SET SCOMP_JARS=%SCOMP_JARS%;.
SET DEST_DIR=lib
REM %XMLBEANS_HOME%\bin\scomp -cp %SCOMP_JARS% -out
%DEST_DIR%\HTML_TABLE.jar -debug html_table.xsd html_table.xsdconfig
%XMLBEANS_HOME%\bin\scomp -cp %SCOMP_JARS% -out
%DEST_DIR%\FURNITURE_TABLE.jar -debug furniture_table.xsd
furniture_table.xsdconfig
can you suggest a way around this feature of XmlBeans?
I have have two XML Schema, furniture_table.xsd and
html_table.xsd (see below) that both define a root
element "table".
Scomp was used to make two JARS, one for unmarshalling
html_table XML instance docs, and another for unmarshalling
furniture_table XML instance docs.
When I try to unmarshal my HTML table, the furniture table
Types get in the way. The HTML JAR must be in the
java execution CLASSPATH *before* the furniture JAR,
otherwise I get a message
org.apache.xmlbeans.XmlException: XML object is not of type D=table
I assume this is because when XmlBeans looks up what class is bound
to <table> it finds html.HTMLTableDocument if HTML_TABLE.jar
is first and furniture.FURNTableDocument if
FURNITURE_TABLE.jar is first.
Any suggestions on how to avoid this CLASSPATH dependency?
Thanks for reading
Max
APPENDIX 1. My source code...
public void test()
{
try
{
System.out.println("Test is beginning...");
HTMLTableDocument htmlTable =
HTMLTableDocument.Factory.parse(new
File("C:/Temp/XmlBeansBug/html_table.xml"));
System.out.println("Parsed OK.");
}
catch( Exception e )
{
e.printStackTrace();
}
finally
{
System.out.println("Test is finished!");
}
APPENDIX 2. The result of running my code
Test is beginning...
org.apache.xmlbeans.XmlException: XML object is not of type D=table
at
org.apache.xmlbeans.impl.store.Root.autoTypedDocument(Root.java:436)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1038)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1022)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:322)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:233)
at html.HTMLTableDocument$Factory.parse(HTMLTableDocument.java:208)
at TestXmlBeans.test(TestXmlBeans.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Test is finished!
APPENDIX 3. My XSDs
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="table">
<xs:annotation>
<xs:documentation>HTML table</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="row" minOccurs="1" maxOccurs="256" >
<xs:complexType>
<xs:sequence>
<xs:element name="cell" type="xs:string" minOccurs="1"
maxOccurs="256"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="table">
<xs:annotation>
<xs:documentation>this is an HTML table</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="leg" minOccurs="1" maxOccurs="4"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
APPENDIX 4. XML instance doc
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Temp\XmlBeansBug\html_table.xsd">
<row>
<cell>Kaczynski </cell>
<cell>Nichols</cell>
</row>
<row>
<cell>Moussaoui<html_table.xsdconfig/cell>
<cell>Yousef</cell>
</row>
</table>
APPENDIX 5. My xsdconfig files...
<?xml version="1.0" encoding="UTF-8"?>
<xb:config
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
<xb:namespace uri="##any">
<xbackage>html</xbackage>
<xbrefix>HTML</xbrefix>
</xb:namespace>
</xb:config>
<?xml version="1.0" encoding="UTF-8"?>
<xb:config
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">
<xb:namespace uri="##any">
<xbackage>furniture</xbackage>
<xbrefix>FURN</xbrefix>
</xb:namespace>
</xb:config>
APPENDIX 6 My BAT file
SET SCOMP_JARS=%XMLBEANS_HOME%\lib\jsr173_1.0_api.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\xmlpublic.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\xbean.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\resolver.jar
SET SCOMP_JARS=%SCOMP_JARS%;%XMLBEANS_HOME%\lib\xbean_xpath.jar
SET SCOMP_JARS=%SCOMP_JARS%;.
SET DEST_DIR=lib
REM %XMLBEANS_HOME%\bin\scomp -cp %SCOMP_JARS% -out
%DEST_DIR%\HTML_TABLE.jar -debug html_table.xsd html_table.xsdconfig
%XMLBEANS_HOME%\bin\scomp -cp %SCOMP_JARS% -out
%DEST_DIR%\FURNITURE_TABLE.jar -debug furniture_table.xsd
furniture_table.xsdconfig