You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Guoliang Cao <ca...@ispsoft.com> on 2001/01/02 20:54:53 UTC

Is this correct to validate a bare xml document? Thanks.

Sorry to bring this up again.

My input is a DOM document object which contains no namespace and
schemaLocation in its root element. I need to validate it. What I'm
doing is

--- doc is the DOM document I want to validate ---
Element root = doc.getDocumentElement();

root.setAttribute("xmlns", mynamespace);
root.setAttribute("xmlns:xsi","http://www.w3.org/1999/XMLSchema-instance");

root.setAttribute("xsi:schemaLocation", mynamespace+"
"+mySchemaLocation);

validate(doc);


It seems not good to do this because an exception is thrown. However, if
I add the namespace stuff into the xml file and validate it,  it's
totally OK.  So I believe xerces doesn't recognize the post-added
xmlns/xmlns:xsi/xsi:schemaLocation  as namespace nodes. Then what kind
of action should I take before validation?


What I'm using is  Xerces 1.2.3/windows 2000.

org.xml.sax.SAXException: [Error] :7:57: Element type "root" must be
declared.

 at .....MyHandler.error(MyHandler.java:21)

 at
org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1092)

 at
org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1258)

 at
org.apache.xerces.validators.common.XMLValidator.validateElementAndAttributes(XMLValidator.java:2737)

 at
org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:835)

 at
org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1853)

 at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1001)

 at
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)

 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:948)

 at ......validateXMLDocument(XMLValidator.java:209)



Re: Is this correct to validate a bare xml document? Thanks.

Posted by Guoliang Cao <ca...@ispsoft.com>.
I've got it.  The classpath is wrong.

> Sorry to bring this up again.
>
> My input is a DOM document object which contains no namespace and
> schemaLocation in its root element. I need to validate it. What I'm
> doing is
>
> --- doc is the DOM document I want to validate ---
> Element root = doc.getDocumentElement();
>
> root.setAttribute("xmlns", mynamespace);
> root.setAttribute("xmlns:xsi","http://www.w3.org/1999/XMLSchema-instance");
>
> root.setAttribute("xsi:schemaLocation", mynamespace+"
> "+mySchemaLocation);
>
> validate(doc);
>
> It seems not good to do this because an exception is thrown. However, if
> I add the namespace stuff into the xml file and validate it,  it's
> totally OK.  So I believe xerces doesn't recognize the post-added
> xmlns/xmlns:xsi/xsi:schemaLocation  as namespace nodes. Then what kind
> of action should I take before validation?
>
> What I'm using is  Xerces 1.2.3/windows 2000.
>
> org.xml.sax.SAXException: [Error] :7:57: Element type "root" must be
> declared.
>
>  at .....MyHandler.error(MyHandler.java:21)
>
>  at
> org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1092)
>
>  at
> org.apache.xerces.validators.common.XMLValidator.reportRecoverableXMLError(XMLValidator.java:1258)
>
>  at
> org.apache.xerces.validators.common.XMLValidator.validateElementAndAttributes(XMLValidator.java:2737)
>
>  at
> org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:835)
>
>  at
> org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1853)
>
>  at
> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1001)
>
>  at
> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
>
>  at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:948)
>
>  at ......validateXMLDocument(XMLValidator.java:209)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org