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 Gus Delgado <gu...@netquotient.com> on 2001/04/17 19:17:04 UTC

Validating...

...xml with external DTD inside your code. I'm kind of new to xerces:
I'm trying to validate some xml I received as a Document against an external
DTD how would I go about doing that with xerces.

This is what I've try so far. I was not successful.

public Element request(Document root){
	OutputFormat    format  = new OutputFormat( root );
      XMLSerializer    serial = new XMLSerializer( format );
      serial.asDOMSerializer();
      serial.serialize( root.getDocumentElement() );

      DOMParser parser = new DOMParser();
      parser.setFeature( "http://xml.org/sax/features/validation", true );
      parser.setFeature( "http://apache.org/xml/features/validation/schema",
true );
}

...The XML has a <!DOCTYPE MORTGAGEDATA SYSTEM
"http://myhost/dtd/Flood.dtd">

what am I doing wrong?

Your help is greatly appreciated...

gus


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


archives for this mailing list

Posted by Gus Delgado <gu...@netquotient.com>.
Does anyone know where the archive for this mailing list is located, I tried
this url http://xml-archive.webweaving.org/

... and it send me to this one:
http://archive.covalent.net

... but still nothing?

anyone?

thanks,
gus


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


RE: Validating...

Posted by Gus Delgado <gu...@netquotient.com>.
I'm running into a new problem, I keep getting an
Error:org.xml.sax.SAXParserException: Element type "ELEMENT_NAME" must be
declared

I get that for every single element in my xml (THE XML DOESN'T HAVE THE DTD
ON IT, I.E. DOCTYPE  NAME SYSTEM "DTD.DTD")

this is a snip of my code:

public class MyDefaultHandler extends DefaultHandler implements ErrorHandler
{

public void validate(InputStream theStream){
...
XMLReader theReader = parser.getXMLReader();
// Activate Validation
String validation = "http://xml.org/sax/features/validation";
theReader.setFeature(validation, true);

 /** Create the InputStream theStream is an InputStream with has xml**/
InputSource iso = new InputSource(theStream);
URL u = new URL("http://myhost/example/mydtd.dtd");
iso.setSystemId(u.toString());

/** Set Handlers **/
theReader.setContentHandler(this);
theReader.setEntityResolver(this);
theReader.setErrorHandler(this);
theReader.parse(iso);
}

public InputSource resolveEntity(String publicId, String systemId)
    throws SAXException
    {
        InputSource i = null;
        if (! systemId.startsWith("http://myhost/example/")) {
            // XML tries to use different DTD
            throw new SAXException("Must use " + SYSTEM_ID_PREFIX
            + "mydtd.dtd for this config file");
        }

        try{
            URL dtdURL = new URL("http://myhost/example/mydtd.dtd");

            if (dtdURL == null) {
                throw new SAXException("Can't find mydtd.dtd");
            }else{
                System.out.println("found DTD");
            }
            i = new InputSource(dtdURL.toString());

        }catch(Exception ssa){}
        return i;
    }

    public void error (SAXParseException e)
        throws SAXException
    {
        System.out.println("ERROR:" + e);
    }

    public void fatalError(SAXParseException e)
        throws SAXException
    {
        System.out.println("FATAL_ERROR:" + e);
    }

    public void warning(SAXParseException e)
        throws SAXException
    {
        System.out.println("WARNING:" + e);
    }

...when I run it, it goes into the error method for the ErrorHandler
interface and it prints out the error above.  Any ideas what am I doing
wrong? How can I register the DTD to validate the xml?  Your help will be
very appeciated, I've been working on this for a while now.  thanks.

Gus Delgado
Consultant
Net Quotienet Consulting Group
e-mail:gus.delgado@netquotient.com
cell: 512-587-6986

-----Original Message-----
From: Andy Clark [mailto:andyc@apache.org]
Sent: Wednesday, April 18, 2001 9:23 PM
To: xerces-j-dev@xml.apache.org
Subject: Re: Validating...


Gus Delgado wrote:
> I'm not really sure how to do that?! is there any sample code that
> I can look at?

  interface org.xml.sax.EntityResolver
  method setEntityResolver

I don't feel like writing yet another sample. Check the mailing
list archives for one of my previous posts on this topic.

--
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Validating...

Posted by Andy Clark <an...@apache.org>.
Gus Delgado wrote:
> I'm not really sure how to do that?! is there any sample code that 
> I can look at?

  interface org.xml.sax.EntityResolver
  method setEntityResolver

I don't feel like writing yet another sample. Check the mailing
list archives for one of my previous posts on this topic.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


RE: Validating...

Posted by Gus Delgado <gu...@netquotient.com>.
I'm not really sure how to do that?! is there any sample code that I can
look at?

thanks
gus

-----Original Message-----
From: Andy Clark [mailto:andyc@apache.org]
Sent: Wednesday, April 18, 2001 3:01 AM
To: xerces-j-dev@xml.apache.org
Subject: Re: Validating...


Gus Delgado wrote:
>       DOMParser parser = new DOMParser();
> [...]
> ...The XML has a <!DOCTYPE MORTGAGEDATA SYSTEM
> "http://myhost/dtd/Flood.dtd">
>
> what am I doing wrong?

Write an entity resolver that will return the DTD that is
referenced in the serialized document. Then just register
it with the parser and you should be good to go.

--
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Validating...

Posted by Andy Clark <an...@apache.org>.
Gus Delgado wrote:
>       DOMParser parser = new DOMParser();
> [...]
> ...The XML has a <!DOCTYPE MORTGAGEDATA SYSTEM
> "http://myhost/dtd/Flood.dtd">
> 
> what am I doing wrong?

Write an entity resolver that will return the DTD that is
referenced in the serialized document. Then just register
it with the parser and you should be good to go.

-- 
Andy Clark * IBM, TRL - Japan * andyc@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org