• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

XML Validation

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, typically in the past when I have validated XML documents, I've done something like this:



Recently though I've started using the Java XML Validation API included with Java 5+. It seems much easier to use the Java XML validation API rather than the DOMParser's validation because 1) the API is simpler and 2) I can easily switch parsers and validation types (i.e. xsd or dtd).

Is there a disadvantage to using the Java XML validation API? I can't see why I wouldn't.

Thanks,
Jeff
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you should use javax.xml... classes, and not rely on any Apache-specific settings or classes. Those had their use before this stuff was standardized as part of JAXP, but now there's no real need to use them any more. (And, indeed, a downside since it makes it harder to switch parsers, should you ever need to do that.)

An example of the canonical way to validate XML is at http://faq.javaranch.com/java/HowToValidateXmlAgainstAnySchema
[ February 20, 2008: Message edited by: Ulf Dittmer ]
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When doing my XML parsing though, I still use other parsers, not the JAXP parsers (i.e. JDOM). Is it a problem to mix and match like that (i.e. use JDOM for reading/writing but using JAXP for validating?)
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't think so. They all use the same parsers underneath anyway. None of those APIs (DOM, XOM, JDOM, dom4j, Jaxen, ...) have their own parsers; they all rely on whatever parser JAXP provides. They may have config settings to override the JAXP parser setting, but you'd still need to provide one for them.
[ February 20, 2008: Message edited by: Ulf Dittmer ]
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

A belated thanks on this topic. I've become a bit more familiar with the JAXP API and it is quite useful. Thanks again.

Jeff
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
I am trying to validate an xml using JAXP.

This is my input xml

When i try to validate this XML, I am getting the following error
This is my xsd

Could you please guide me where I am going wrong...
Thanks in advance...

[ May 13, 2008: Message edited by: Shanthi Murugeson ]

[ May 13, 2008: Message edited by: Shanthi Murugeson ]
[ May 13, 2008: Message edited by: Shanthi Murugeson ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The XML snippet you posted is not valid XML - it uses single quotes around attribute value instead of double quotes.
 
Nothing? Or something? Like this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic