Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > why is this not validating?

Reply
Thread Tools

why is this not validating?

 
 
scorpion
Guest
Posts: n/a
 
      04-29-2004
I have this problem that an xml instance is validated correctly
by xml tools, but not with my simple code, by setting the
validating flag to true.

--------------- Schema -----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xml:lang="EN"
targetNamespace="http://www.mydomain.com/demo/Test"
xmlns:test="http://www.mydomain.com/demo/Test"
xmlnss="http://www.w3.org/2001/XMLSchema">

<xs:element name="TestO" type="test:TestType"/>
<xs:complexType name="TestType">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Value" type="xs:integer"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:schema>

---------------- Instance ----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<test:TestO xmlns:test="http://www.mydomain.com/demo/Test"
xsi:schemaLocation="http://www.mydomain.com/demo/Test
file:///home/csp/workspace/test-java/test.xsd"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance" id="example-ncname">
<test:Name>string</test:Name>
<test:Value>1</test:Value>
</test:TestO>

This is validating correctly using XMLBuddy, XMLSpy, etc. But when
I try to do with the following code

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setErrorHandler(new SimpleErrorHandler());

Document document = db.parse(new
File("/home/csp/workspace/test-java/test.xml"));

It's reporting the errors

org.xml.sax.SAXParseException: Document root element "test:TestO", must
match DOCTYPE root "null".
at
org.apache.xerces.util.ErrorHandlerWrapper.createS AXParseException(Unknown
Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(U nknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
at
org.apache.xerces.impl.dtd.XMLDTDValidator.rootEle mentSpecified(Unknown
Source)
at
org.apache.xerces.impl.dtd.XMLDTDValidator.handleS tartElement(Unknown
Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startEl ement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanStartElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$Cont entDispatcher.scanRootElementHook(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(U nknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at test.resolver.TestIdResolver.main(TestIdResolver.j ava:36)
org.xml.sax.SAXParseException: Document is invalid: no grammar found.
at
org.apache.xerces.util.ErrorHandlerWrapper.createS AXParseException(Unknown
Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(U nknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
at
org.apache.xerces.impl.dtd.XMLDTDValidator.handleS tartElement(Unknown
Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startEl ement(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanStartElement(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl$Cont entDispatcher.scanRootElementHook(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl$FragmentContentDispatcher.dispatch(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(U nknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at test.resolver.TestIdResolver.main(TestIdResolver.j ava:36)

What's wrong with that code?

TIA
 
Reply With Quote
 
 
 
 
scorpion
Guest
Posts: n/a
 
      04-29-2004
Forget about this. Had to use "dbf.setAttribute()" instead.

scorpion wrote:
> I have this problem that an xml instance is validated correctly
> by xml tools, but not with my simple code, by setting the
> validating flag to true.
>
> --------------- Schema -----------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema elementFormDefault="qualified" xml:lang="EN"
> targetNamespace="http://www.mydomain.com/demo/Test"
> xmlns:test="http://www.mydomain.com/demo/Test"
> xmlnss="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="TestO" type="test:TestType"/>
> <xs:complexType name="TestType">
> <xs:sequence>
> <xs:element name="Name" type="xs:string"/>
> <xs:element name="Value" type="xs:integer"/>
> </xs:sequence>
> <xs:attribute name="id" type="xs:ID"/>
> </xs:complexType>
> </xs:schema>
>
> ---------------- Instance ----------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <test:TestO xmlns:test="http://www.mydomain.com/demo/Test"
> xsi:schemaLocation="http://www.mydomain.com/demo/Test
> file:///home/csp/workspace/test-java/test.xsd"
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> id="example-ncname">
> <test:Name>string</test:Name>
> <test:Value>1</test:Value>
> </test:TestO>
>
> This is validating correctly using XMLBuddy, XMLSpy, etc. But when
> I try to do with the following code
>
> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
> dbf.setValidating(true);
> DocumentBuilder db = dbf.newDocumentBuilder();
> db.setErrorHandler(new SimpleErrorHandler());
>
> Document document = db.parse(new
> File("/home/csp/workspace/test-java/test.xml"));
>
> It's reporting the errors
>
> org.xml.sax.SAXParseException: Document root element "test:TestO", must
> match DOCTYPE root "null".
> at
> org.apache.xerces.util.ErrorHandlerWrapper.createS AXParseException(Unknown
> Source)
> at org.apache.xerces.util.ErrorHandlerWrapper.error(U nknown Source)
> at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
> at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
> at
> org.apache.xerces.impl.dtd.XMLDTDValidator.rootEle mentSpecified(Unknown
> Source)
> at
> org.apache.xerces.impl.dtd.XMLDTDValidator.handleS tartElement(Unknown
> Source)
> at org.apache.xerces.impl.dtd.XMLDTDValidator.startEl ement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanStartElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentScannerImpl$Cont entDispatcher.scanRootElementHook(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanDocument(Unknown
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
> at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(U nknown Source)
> at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
> at test.resolver.TestIdResolver.main(TestIdResolver.j ava:36)
> org.xml.sax.SAXParseException: Document is invalid: no grammar found.
> at
> org.apache.xerces.util.ErrorHandlerWrapper.createS AXParseException(Unknown
> Source)
> at org.apache.xerces.util.ErrorHandlerWrapper.error(U nknown Source)
> at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
> at org.apache.xerces.impl.XMLErrorReporter.reportErro r(Unknown Source)
> at
> org.apache.xerces.impl.dtd.XMLDTDValidator.handleS tartElement(Unknown
> Source)
> at org.apache.xerces.impl.dtd.XMLDTDValidator.startEl ement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanStartElement(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentScannerImpl$Cont entDispatcher.scanRootElementHook(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl$FragmentContentDispatcher.dispatch(Unknown
> Source)
> at
> org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanDocument(Unknown
> Source)
> at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
> at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(U nknown Source)
> at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
> at test.resolver.TestIdResolver.main(TestIdResolver.j ava:36)
>
> What's wrong with that code?
>
> TIA

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM



Advertisments