Once upon a time I had a valid doctype and valid XML. I put the former on top of the latter, cntrl-s'd and behold: all was as all should be. Nowadays I have a valid schema (custom built for my still valid XML). I tried my same tried and true approach - but alas, no success.
I get different errors with each different validator I use, and yet new errors from browsers I submit it to (but that makes sense). So I'm not sure which I should give to be most helpful. Validome says:
Can not find declaration of element 'xs:schema'.
and
开发者_JAVA百科The markup in the document following the root element must be well-formed.
(but it is!)
If it'd be useful to have the XML and schema, please don't hesitate to ask, I just thought that since they are both W3 valid and lengthy, I would try leaving them out at first. All I'm doing is putting the schema on top of the XML and sending it through the validator/browser.
Thanks!
@Nona A schema is a well-formed document and so is your instance. If, however, you concatenate them the result is no longer well-formed.
If what you have is:
<xs:schema ...>...</xs:schema>
<myxml ...>...</myxml>
this is not well-formed (no single root element)
The reason why the DTD approach is different is that the internal subset is specifically allowed to be prepended to the root element. So:
<DOCTYPE myxml [
... my DTD ...
]>
<myxml ...>...</myxml>
is well formed.
Unfortunately it is not completely trivial to associate a schema with an instance. You may have to look at xsi:schema-location
.
UPDATE Unfortunately the answer will depend on the software framework you use. AFAIK there is no way of packaging a document and a schema such that any software will accept and attempt to validate. This is why schemas are much more effort than DTDs.
Here is a simple site where you can submit the two documents and test.
Anything beyond that may need a knowledge of the software. There will be different approaches according to whether you are using ORACLE, Microsoft, etc. This may be done by calling methods to load the document, load the schema and then validate, or setting properties (as can be done in Xerces).
The answer may depend on why you are doing this. If you are submitting documents to the owner of the schema then they will probbaly have a validation system. If you have to valiadte against someone else's schema then you will need to get schemavalidation software and run this. Are you on MS or Unix/Java?
MORE UPDATE Suggest What's the best way to validate an XML file against an XSD file? As they say there is no ultra-simple approach.
Just a stab in the dark, but do you have the XML Schema namespace prefix declared on the root element? It's xmlns:xs="http://www.w3.org/2001/XMLSchema". If a namespace prefix is not bound to a namespace name, then the document is invalid.
At the risk of stating the obvious, you might want to consider reasons why the declaration of element xs:schema cannot be found by the validator.
The second error suggests that there is an angle bracket missing somewhere, or that there are some elements that are not nested properly.
精彩评论