Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Schema parsing

 
ruhail akhtar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am struggling to find out how can I can I make use of the XML schema, when I parse my XML document with SAX parser. I have to need to find out types and constrainsts of the elements which are defined in XML schema of the XML document.
I am kinda thinking I have to write XML schema parser as well. Any thoughts or suggestions will be appreciated.
Regards,
Akhtar
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The schema document can be used to validate the XML document while parsing. It's basically invisible to you except for the parse() method throwing a SAXParseException if the XML instance doesn't conform to the specified XML Schema.
Take a look at HowToValidateXmlAgainstAnySchema in our wiki.
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah. parsing and validating are two different things.
if you just want to get straight to the core of what's *in* a (perhaps valid) dtd, and passively perform some lightweight validation along the way - don't write your own parser, try something like wutka's or bourret's dtdparser first.
Likewise there are articles about perl/php versions of this (if your box has php) at webreference or zend (expat).
hth
 
Clarence Schabe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using the sample code provided by the link in the above response:

HowToValidateXmlAgainstAnySchema

but I am getting the error:

Feature not recognized: http: //xml.org/sax/features/validation

which was obviously in response to the line of code:

parser.setFeature("http: //xml.org/sax/features/validation", true);

Can someone help?

Also, does anyone know how to reference a schema that is just on the local development machine - i.e. the line of code:

parser.setProperty("http: //apache.org/xml/properties/schema/external-schemaLocation",
"http://domain.com/mynamespace mySchema.xsd");

How do I point to my schema if it is only on my local development machine at say c:\myFolder\myXsd.xsd?

Many Thanks!
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Feature not recognized: http: //xml.org/sax/features/validation

which was obviously in response to the line of code:

parser.setFeature("http: //xml.org/sax/features/validation", true);

Apparently your parser doesn't recognize that particular feature. Solution? Switch into using another parser, Xerces, for example.

Also, does anyone know how to reference a schema that is just on the local development machine - i.e. the line of code:

parser.setProperty("http: //apache.org/xml/properties/schema/external-schemaLocation",
"http://domain.com/mynamespace mySchema.xsd");

How do I point to my schema if it is only on my local development machine at say c:\myFolder\myXsd.xsd?

Try replacing "mySchema.xsd" with your absolute file path. Notice that the domain.com stuff in that example is the namespace, not the physical location of the schema document.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic