473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

validating XML against schema using JDOM

Hi

I am validating an xml document against schema .
when i am passing the xml file location as an input to the parse method

String XmlDocumentUrl="E:/books.xml";
parser.parse(XmlDocumentUrl);

it is working fine.

but how can i do that if i need to pass a xml document content instead
of the file location.

String XmlDocumentUrl="E:/books.xml";
InputSource inputSource = new InputSource(new
ByteArrayInputStream(XmlDocumentUrl.getBytes()));
parser.parse(inputSource);

The error is Cannot find the declaration of element 'Books'
'Books' is my root element.

Any help is greatly appreciated.
Thanks.

Dec 29 '05 #1
2 2103
srujana wrote:
Hi

I am validating an xml document against schema .
when i am passing the xml file location as an input to the parse method

String XmlDocumentUrl="E:/books.xml";
parser.parse(XmlDocumentUrl);

it is working fine.

but how can i do that if i need to pass a xml document content instead
of the file location.

String XmlDocumentUrl="E:/books.xml";
InputSource inputSource = new InputSource(new
ByteArrayInputStream(XmlDocumentUrl.getBytes()));
parser.parse(inputSource);

The error is Cannot find the declaration of element 'Books'
'Books' is my root element.


It could be something with base URI?

With your first method, the parser has a chance to resolve relative URIs
in your document, in order to load other resources, such as the schema.
If the document contains this schema-location element thing (can't
remember its name) with schema location "foo.xsd", the parser will
resolve that to e:/foo.xsd . With your second method it doesn't have a
chance, because it never heard about e:/ .

You can probably set the base URI on the InputSource that you use,
letting the parser know the base URI. If you don't want to use
InputSources at all, you have to give the parser a schema location hint
by calling some method on it, or make your own entity resolver and have
to parser use that.

Soren
Dec 31 '05 #2
srujana wrote:
String XmlDocumentUrl="E:/books.xml";
InputSource inputSource = new InputSource(new
ByteArrayInputStream(XmlDocumentUrl.getBytes()));


This will create an input stream from the bytes in the string
"E:/books.xml", not from the bytes in the file referenced by "E:/books.xml".

--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Dec 31 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Will | last post by:
I have been having problems validating an XForms document against the XForms schema located at http://www.w3.org/MarkUp/Forms/2002/XForms-Schema.xsd. I have reduced the XForm to its bare bones...
0
by: kyancy | last post by:
Hello All. We have several XML schemas to describe common component document parts. We then create new XML schemas as necessary that use "xsd:import schemaLocation=whateverLocation.." to include...
6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
1
by: Christian | last post by:
Hi, I load an Xml-file "customers.xml" into a DataSet (works fine) but then how do I validate it against a schema (e.g. customers.xsd) ? my customers.xml: <?xml version="1.0"...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
I wrote a method to validate and xml file against a schema. If the file does not conform to the schema, it throws an error. It works fine except for one curious thing. If I try to validate an...
4
by: agda.karlberg | last post by:
Hello, I need to remove the DTD reference from an xml document, the reason for this is that we want to validate against a schema instead (which we have locally). It takes up to a minute to fetch...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.