|
From: Stefan B. <bo...@ap...> - 2006-12-22 05:30:17
|
On Thu, 21 Dec 2006, James Abley <jam...@gm...> wrote:
> I'm writing a patch for consideration that will handle schema
> validation.
[please use CVS diff to create patches, it is easier to see what has
changed that way]
> So I would like to set some properties on a Validator like this:
>
> validator = new Validator(new FileReader(xmlFile));
> validator.setSchemaNamespace("http://www.example.com/xmlns/books");
> validator.setSchemaURL(xsdFile.toURL());
> validator.useXMLSchema(true);
>
> validator.assertIsValid();
This is something you'd use a catalog for. See OASIS[1] and the XML
resolver in xml-commons at Apache. Ant supports a simple Map based
catalog internally as well as one based on the XML resolver. I was
thinking about adding this in a similar way to XMLUnit.
> This is what my patch is aiming to provide. Comments on the API and
> intended usage are welcome.
rather than pairs of setSchemaNamespace/setSchemaURI I'd prefer a
single method, something like
public void setSchemaLocation(String nsURI, URL nsURL)
or some kind of Map or - see above - a full catalog implemention.
> In developing the tests for this patch though, I seem to have hit a
> bug, and was hoping someone could help me see what I'm doing wrong.
> The below tests fail, although I don't think they should. I can't
> see what properties I should be setting that would cause it to pass.
> private String expected = "<root xmlns='http://www.example.com/xmlns/example'" + "
> + xmlns:xsi='http://exampe.com/xmlns/not/schema-instance/namespace'/>";;
> private String actual = "<root xmlns='http://www.example.com/xmlns/example' />";
Why do you expect them to be different? The
http://exampe.com/xmlns/not/schema-instance/namespace is never used.
Cheers
Stefan
Footnotes:
[1] http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
|