• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Schema parsing

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic