[jdom-interest] Help:How to make JDOM work with validation on?
Miguel Angel Medina Lopez
mamedina at logic-factory.com
Tue Jun 26 00:06:36 PDT 2001
Hi:
I validate xml document against schemas with JDOM. The next samples is with
beta6 and I don't know if work with beta 7.
After you create a instante of SAXBuilder with validate to true, you must
indicate the schema in your XML file and the validation is automatic when
you call method buid of SAXBuilder object. You indicate the schema URL with
the nexy line at top of your XML document.
<?xml version="1.0"?>
<ROOT xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema_url_or_file.xsd">
If you create the document with the JDOM API methods, you must write the
next lines to include this attribute to the document:
root = new Element("ROOT");
root.addAttribute(new
Attribute("noNamespaceSchemaLocation","schema_url_or_file.xsd",Namespace.get
Namespace("xsi","http://www.w3.org/1999/XMLSchema-instance")));
doc = new Document(root);
I hope this help you
-------------------------------------------------------------
Miguel Ángel Medina López
Logic Factory: www.logic-factory.com
Granada - España
----- Original Message -----
From: "Nagulapalli, Srinivas" <Srinivas_Nagulapalli at CINFIN.com>
To: <jdom-interest at jdom.org>
Sent: Thursday, July 19, 2001 4:42 PM
Subject: [jdom-interest] Help:How to make JDOM work with validation on?
>
> Hi,
> Here are the sample files I took from www.w3c.org site's XML primer. It
has
> a schema file: ipo.xsd and the sample xml file called ipo.xml.
> And when I used the JDOM API using SAX Parser to simply read and output
the
> XML
> file _without_ validation, it works fine! But when I turn on validation
> ( by uncommenting the line that has new SAXBuilder(true) in the code),
then
> I get the following error:
>
> org.xml.sax.SAXParseException: Element type "ipo:purchaseOrder" is not
> declared. at
> org.apache.crimson.parser.Parser2.error(Parser2.java:3013) at
> org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1308) at
> org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:499) at
> org.apache.crimson.parser.Parser2.parse(Parser2.java:304) at
> org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433) at
> org.jdom.input.SAXBuilder.build(SAXBuilder.java:287) at
> org.jdom.input.SAXBuilder.build(SAXBuilder.java:682) at
> cinfine.Conduct.main(Conduct.java:60)
>
>
> I am surprised because the sample files are from w3c.org site and the
java
> code I have
> is pretty much the cut down version of sample file from JDOM install. I
> appreciate
> any help, pointers, insights or suggestions.
> Thanks
> -Srini
>
>
----- Original Message -----
From: "Miguel Angel Medina Lopez" <migue at logic-factory.gr>
To: "Nagulapalli, Srinivas" <Srinivas_Nagulapalli at CINFIN.com>;
<jdom-interest at jdom.org>
Sent: Tuesday, June 26, 2001 8:24 AM
Subject: Re: [jdom-interest] Help:How to make JDOM work with validation on?
> Hi:
>
> I validate xml document against schemas with JDOM. The next samples is
with
> beta6 and I don't know if work with beta 7.
> After you create a instante of SAXBuilder with validate to true, you must
> indicate the schema in your XML file and the validation is automatic when
> you call method buid of SAXBuilder object. You indicate the schema URL
with
> the nexy line at top of your XML document.
>
> <?xml version="1.0"?>
> <ROOT xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
>
xsi:noNamespaceSchemaLocation="schema_url_or_file.xsd">
>
> If you create the document with the JDOM API methods, you must write the
> next lines to include this attribute to the document:
>
> root = new Element("ROOT");
> root.addAttribute(new
>
Attribute("noNamespaceSchemaLocation","schema_url_or_file.xsd",Namespace.get
> Namespace("xsi","http://www.w3.org/1999/XMLSchema-instance")));
>
> doc = new Document(root);
>
> I hope this help you
>
> -------------------------------------------------------------
> Miguel Ángel Medina López
> Logic Factory: www.logic-factory.com
>
>
> ----- Original Message -----
> From: "Nagulapalli, Srinivas" <Srinivas_Nagulapalli at CINFIN.com>
> To: <jdom-interest at jdom.org>
> Sent: Thursday, July 19, 2001 4:42 PM
> Subject: [jdom-interest] Help:How to make JDOM work with validation on?
>
>
> >
> > Hi,
> > Here are the sample files I took from www.w3c.org site's XML primer. It
> has
> > a schema file: ipo.xsd and the sample xml file called ipo.xml.
> > And when I used the JDOM API using SAX Parser to simply read and output
> the
> > XML
> > file _without_ validation, it works fine! But when I turn on validation
> > ( by uncommenting the line that has new SAXBuilder(true) in the code),
> then
> > I get the following error:
> >
> > org.xml.sax.SAXParseException: Element type "ipo:purchaseOrder" is not
> > declared. at
> > org.apache.crimson.parser.Parser2.error(Parser2.java:3013) at
> > org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1308) at
> > org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:499) at
> > org.apache.crimson.parser.Parser2.parse(Parser2.java:304) at
> > org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433) at
> > org.jdom.input.SAXBuilder.build(SAXBuilder.java:287) at
> > org.jdom.input.SAXBuilder.build(SAXBuilder.java:682) at
> > cinfine.Conduct.main(Conduct.java:60)
> >
> >
> > I am surprised because the sample files are from w3c.org site and the
> java
> > code I have
> > is pretty much the cut down version of sample file from JDOM install. I
> > appreciate
> > any help, pointers, insights or suggestions.
> > Thanks
> > -Srini
> >
> >
>
More information about the jdom-interest
mailing list