Namespaces / apache.crimson.parser / BASDA XML / HELP!!

This is probably an easy question but I can't find anyone to help me.

I am using the apache.crimson.parser to parse and validate an Xml doc against the BASDA eBIS-XML purchase order schema but i can't get the Namespaces right.

I have this at present for the Xml doc;

<Order xmlns ="urn:schemas-microsoft-com:xml-data"

xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="urn:schemas-microsoft-com:xml-data

http://www.cs.aston.ac.uk/hillsm/project/eBIS-XML_Order_v3.01.xml">

....and this for the schema;

<Schema name="eBIS-XML_Order_v3.01.xml"

xmlns="urn:schemas-microsoft-com:xml-data"

xmlns:dt="urn:schemas-microsoft-com:datatypes">

Does anyone have any ideas?

[779 byte] By [hillsteven] at [2007-9-26 1:32:06]
# 1

Steven,

let me first note that I'm not familiar with the specific Schema you mention here (apparently from M$), and it would have been helpful to see at least part of it in your posting, because it seems abnormal that Microslob uses the conventional xsd namespace for schema declarations (although it wouldn't surprise me).

Anyways, let's do a first version without the xsd name space.

The declarations in your xml file are correct.

In the schema file, the first error is, that schema is misspelled as Schema. Secondly, schema does not allow a name attribute (get rid of it). There is also no reference to the namespace "http://www.w3.org/2001/SMLSchema". So, the default namespace has to be changed to that. The targetNamespace attribute specifies that this schema applies to the specified name space. Putting it all together:

<?xml version="1.0"?>

<schema xmlns="http://www.w3.org/2001/XMLSchema"

targetNamespace="urn:schemas-microsoft-com:xml-data"

xmlns:dt="urn:schemas-microsoft-com:datatypes">

<!-- let's have fun and declare an Order element that would work with just one

order element defined in the xml file. -->

<element name="Order" type="string"/>

</schema>

So this would validate OK with this xml file (provided that ..../eBIS-XML_Order_v3.01.xml is the above schema file):

<?xml version="1.0"?>

<Order xmlns ="urn:schemas-microsoft-com:xml-data"

xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="urn:schemas-microsoft-com:xml-data

http://www.cs.aston.ac.uk/hillsm/project/eBIS-XML_Order_v3.01.xml">

</Order>

So, in this example, the default namespace in the schema is set to "http://www.w3.org/2001/XMLSchema" and the targetNamespace attribute points to the xml file's default name space.

However, the standard way of doing things differs. You certainly should not (mis-)set the schema's default name space to "http://www.w3.org/2001/XMLSchema".

I do not know in what way Microsoft limits you, but I strongly recommend something along these lines in order to not have regrets, headache and coffein and nicotine addiction lateron:

<?xml version="1.0"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns="urn:schemas-microsoft-com:xml-data"

xmlns:dt="urn:schemas-microsoft-com:datatypes"

targetNamespace="urn:schemas-microsoft-com:xml-data">

<xsd:element name="Order" type="xsd:string"/>

</xsd:schema>

Also, in order to avoid confusion, Schema files should have the extension xsd - a minor sidepoint.

Hope that helps,

Leo.

lk555 at 2007-6-29 1:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thanks for getting back to me Leo.

I've tryed what you suggested but no luck. Perhaps a copy of the error stack and the schema might help.

The errors are:-

project10 ~/project>java ValidXML test.xml

** Parsing error, line 7, uri file:/eas/d202/hillsm/project/test.xml

Element type "Order" is not declared.

org.xml.sax.SAXParseException: Element type "Order" is not declared.

at org.apache.crimson.parser.Parser2.error(Parser2.java, Compiled Code)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java, Compiled Code)

at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java, Compiled Code)

at org.apache.crimson.parser.Parser2.parse(Parser2.java, Compiled Code)

at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java, Compiled Code)

at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java, Compiled Code)

at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java, Compiled Code)

at DTT.makeDoc(DTT.java, Compiled Code)

at ValidXML.main(ValidXML.java, Compiled Code)

null

The Schema document is located at:-http://194.164.46.55/schema/eBIS-XMLschema_order_v3.01.xml and is a standard BASDA (http://www.oasis-open.org/cover/ebis-xml.html) Purchase Order - I haven't built it myself.

My new xml doc looks like:-

<?xml version='1.0'?>

<!-- A test BASDA eBIS-XML file -->

<!DOCTYPE Order>

<Order xmlns ="urn:schemas-microsoft-com:xml-data"

xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="urn:schemas-microsoft-com:xml-data

http://www.cs.aston.ac.uk/~hillsm/project/eBIS-XMLschema_order_v3.01.xsd">

<OrderHead>

</OrderHead>

.........etc

...and I have tryed

<schema xmlns="http://www.w3.org/2001/XMLSchema"

targetNamespace="urn:schemas-microsoft-com:xml-data"

xmlns:dt="urn:schemas-microsoft-com:datatypes">

<ElementType name="Order" content="eltOnly" order="seq">

<element type="OrderHead"/>

<element type="OrderReferences

" minOccurs="0

" maxOccurs="1

"/>

...... etc

for the schema doc

I'm stumped.

Steve

hillsteven at 2007-6-29 1:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
PS. I have tryed removing the DOCTYPE declaration in the xml doc so that the schema can be seen but I still get the same error.Steve
hillsteven at 2007-6-29 1:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Steven,

I'm not very familiar with Crimson and I do not know how this implementation conforms with the current Schema recommendation. I quickly ran a (crimson) test program and experienced problems with the stuff I posted above. I quickly checked on xml.apache.org but couldn't find any reference to the schema support.

However, my preferred parser is Xerces, and with Xerces the above samples parsed just fine. So, I can only recommend to dig into your (or Sun's) documentation on Crimson - or switch to Xerces.

In case you want to do the latter you can get it at http://xml.apache.org. And you would run your test program the following way [I assume, you're using JAXP to instantiate a parser]:

project10 ~/project>java

-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl

-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl

ValidXML test.xml

I don't want to discriminate against Crimson, but other people in this forum complained about its buggyness.

Anyways,

hope that helps,

Good luck.

lk555 at 2007-6-29 1:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
One more thing. You'd need to turn on namspace awareness by:factory.setNamespaceAware(true); Good luck.
lk555 at 2007-6-29 1:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Steve, after taking a closer look at the BASDA file, I must admit, I don't have a clue. Maybe this conforms to an older schema recommendation, I don't know, I'm not familiar with XML Schema's evolution. It certainly doesn't look like anything in the current schema recommendation, so my hint about the schema name space "http://www.w3.org/2001/XMLSchema" will probably break any attempt to parse this correctly, because it refers to a recent recommendation.

I case you're interested, it should look like something along these lines:

http://www.w3.org/TR/xmlschema-0/#POSchema

Good luck.

lk555 at 2007-6-29 1:32:39 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...