• 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 validation with the java 5

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I try to validate a a XML file using the JAXP from java 5. My validation look like :


but i run on a failure, on the root element.

I do something wrong ?

Regards,
M
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of failure? Is the document you're trying to validate actually valid according to the schema?

Sample code for Schema validation can also be found here.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf

Thanks for your answer. My problem is quite strange, I have an extern validation scheme - an xsd file and I try to validate with this scheme a Document. The Document is created at run time (it is not loaded from a file).
The next code snippet shows how I create the Document and its root node.


My validation does not find the root. I get an exception like :
Exception in thread "main" org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'Parameterset'.

where the Parameterset is the name for my root.
Even more strange if I wrote the generated document in to a file and I reload it (with docBuilder.parse(new File(file)) ) it works.

Why I can not validate the run time generated document ?

Regards M
 
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
That's hard to say without seeing the XML and the Schema.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I post you only a simplified version of my scheme

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation>Schema for Project PDC</xsd:documentation>
</xsd:annotation>
<!--____ Parameters _____-->
<xsd:element name="Parameterset">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Parameter" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Regards,
M
[ July 11, 2007: Message edited by: Mihai Radulescu ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it picking this XSD for validation?
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure this is considerable or not but you have mis spelled your method ( missing 'l' in buildRoot method name)..



Thanks,
Ugender
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Rahul, yes I use the XSD file for validation. The file is pretty big that why I post just one snippet. This sniper is enough to generate the SAXException (because it does not find the root node).

Ugender, thanks for tip.

In the mean time I do some research and I find a solution for my problem but I still can not explain it. It is like this : if I create the DOM document at run time and I validate it I get a SAXException but if I serialize the DOM in to a file and I parse this file back in to a DOM document, the validation works with the new parsed DOM. Quite strange.
This lead me to a conclusion - the DOM build at run time is wrong, but I don't see any error.
How about you guys ?

Regards,
M
 
crispy bacon. crispy 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