Hi,
as mentioned above I'd like to validate a simple XML-document with a simple
DTD.
For this, I use Java and Xerces.
But, when I have tags of this form:
<tag>some characters in here</tag>
Xerces always complains with:
org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters
are not allowed in schema elements other than 'xs:appinfo' and
'xs:documentation'. Saw 'some characters in here'.
The XML-doc is this:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE durchwahlnummer SYSTEM "mydtd.dtd">
<mytag>123456</mytag>
------------
The DTD mydtd.dtd that:
<!ELEMENT mytag (#PCDATA)>
------------
As you can see, the mytag-tag is explicitly declared as PCDATA type, so the
error with "non-Whitespace characters" should actually not occur.
------------
The small Java-Program:
[..]
try {
DOMParser parser = new DOMParser();
parser.setErrorHandler(new ParserError());
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.parse(myDocument);
doc = parser.getDocument();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXNotRecognizedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
[..]
------------
The DTD-validation is turned on.
(parser.setFeature("http://xml.org/sax/features/validation", true);)
Does anyone know what's wrong and can help?
--
Cheers
Georg 7 13321
In article <dh**********@news01.versatel.de>,
Georg J. Stach <VO****************@gmx.de> wrote: Xerces always complains with: org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'some characters in here'.
It seems to be treating your document as an XML schema rather than an
instance to be validated, but I have no idea what you are doing wrong.
-- Richard
Richard Tobin wrote: It seems to be treating your document as an XML schema rather than an instance to be validated, but I have no idea what you are doing wrong.
That's my assumption, too.
However, according to the Xerces page on [1] (read there "What validation
behavior do I expect from the default parser configuration?") the code
should be right.
Maybe this turns out to be a more Xerces-specific question.
If somebody has further hints, don't hesitate to reply.
[1] http://xml.apache.org/xerces2-j/faq-pcfp.html
Cheers
Georg
Georg J. Stach wrote: Hi,
as mentioned above I'd like to validate a simple XML-document with a simple DTD. For this, I use Java and Xerces.
Don't. If you want standalone validation with a DTD, use a standalone
validating parser like onsgmls or rxp.
But, when I have tags of this form:
<tag>some characters in here</tag>
Xerces always complains with: org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'some characters in here'.
The XML-doc is this:
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE durchwahlnummer SYSTEM "mydtd.dtd"> <mytag>123456</mytag>
------------
The DTD mydtd.dtd that:
<!ELEMENT mytag (#PCDATA)>
The name you declare in the Document Type Declaration must be the
same as the name of the root element type. Change your XML file to
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE mytag SYSTEM "mydtd.dtd">
<mytag>123456</mytag>
(or change the DTD to declare durchwahlnummer instead).
As you can see, the mytag-tag is explicitly declared as PCDATA type, so the error with "non-Whitespace characters" should actually not occur.
Your validator isn't giving you the whole story. If I test your original
with onsgmls, I get a much more explicit report:
$ onsgmls -wxml -s -E 5000 /usr/share/sgml/xml.dcl test.xml onsgmls:/usr/share/sgml/xml.dcl:1:W: SGML declaration was not implied onsgmls:test.xml:2:44:E: DTD did not contain element declaration for
document type name onsgmls:test.xml:3:6:E: document type does not allow element "mytag" here onsgmls:test.xml:3:22:E: no document element SGML validation exited abnormally with code 1 at Sun Sep 25 15:14:21 $
///Peter
Hi Peter! Don't. If you want standalone validation with a DTD, use a standalone validating parser like onsgmls or rxp.
What reasons speak against the use of Xerces?
The name you declare in the Document Type Declaration must be the same as the name of the root element type. Change your XML file to
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE mytag SYSTEM "mydtd.dtd"> <mytag>123456</mytag>
(or change the DTD to declare durchwahlnummer instead).
uuups, well I adapted the DTD for this newsgroup messages ;-) In real the
root element and Document Type are the same. This doesn't change anything
about Xerces' behaviour to complain, unfortunately...
Your validator isn't giving you the whole story. If I test your original with onsgmls, I get a much more explicit report: [...]
I see, _that_ could be one reason no to use Xerces, hum? ;-)
I'll have a look on onsgmls.
But actually I cannot imagine that Xerces isn't able to validate against a
DTD. There must be a quite simple error in anywhere I haven't found... in
most cases the problem isn't the application but the programmer ;-)
Georg
Georg J. Stach wrote: What reasons speak against the use of Xerces?
Xerces is a library, not a ready-to-use command line tool.
Georg J. Stach wrote: Hi Peter!
Don't. If you want standalone validation with a DTD, use a standalone validating parser like onsgmls or rxp. What reasons speak against the use of Xerces?
None: the other two I mention were merely suggestions. If Xerces
runs standalone, unassisted, from the command line, then by all
means use it. But AFAIK it's an API, with a wrapper in Java2, C++,
or Perl. Which is a fine thing, but it's not a standalone parser-
validator. To make an adequate test where there is an unexplained
error, you need to remove all extraneous bits and get down the to
bare bones: an XML file, a DTD, and a parser.
uuups, well I adapted the DTD for this newsgroup messages ;-) In real the root element and Document Type are the same.
That changes the problem entirely. Please post the accurate example.
///Peter
Hi Georg,
I notice your declaration is a wrong one :
<!DOCTYPE durchwahlnummer SYSTEM "mydtd.dtd">
it should be
<!DOCTYPE mytag SYSTEM "mydtd.dtd">
Hope it helps,
Best regards,
A.Brillant http://www.editix.com -- XML Editor and XSLT Debugger
Georg J. Stach wrote: Hi,
as mentioned above I'd like to validate a simple XML-document with a simple DTD. For this, I use Java and Xerces. But, when I have tags of this form:
<tag>some characters in here</tag>
Xerces always complains with: org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'some characters in here'.
The XML-doc is this:
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE durchwahlnummer SYSTEM "mydtd.dtd"> <mytag>123456</mytag>
------------
The DTD mydtd.dtd that:
<!ELEMENT mytag (#PCDATA)>
------------
As you can see, the mytag-tag is explicitly declared as PCDATA type, so the error with "non-Whitespace characters" should actually not occur.
------------ The small Java-Program:
[..] try { DOMParser parser = new DOMParser(); parser.setErrorHandler(new ParserError());
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.parse(myDocument); doc = parser.getDocument();
} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXNotRecognizedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXNotSupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); }
} [..]
------------
The DTD-validation is turned on. (parser.setFeature("http://xml.org/sax/features/validation", true);)
Does anyone know what's wrong and can help?
-- Cheers Georg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: bugbear |
last post by:
Subject pretty much says it all. I'd like to
parse XML (duh!) using Xerces (because its fast,
and reliable, and comprehensive, and supports lots
of features).
I'd like to conform to standards...
|
by: Bekkali Hicham |
last post by:
hi, i have downloaded the latest version 2.4 of Xerces, and unziped it, i
end up with a diectory hierarchy like this
c:\xerces-2_4_0\XercesImpl.jar
c:\xerces-2_4_0\XercesSamples.jar...
|
by: Ole Hedegaard |
last post by:
Hi,
I've been looking into the Xerces documentation, and to my surprise it seems
that it is impossible to validate an XML document againts an XML Schema
without having a schemaLocation (or...
|
by: Kevin Partin |
last post by:
I have downloaded the latest Xerces-J files from Apache.org and am
trying to use them to validate an xml data file against a schema that
I wrote. Can someone please provide me with the java command...
|
by: Waseem |
last post by:
Hi
I have looked and tried everything and i still cant sort this out i
have no idea why this wont work
I am using Xerces Perl on Windows and Debian to try this and it wont
work on both of...
|
by: edkawas |
last post by:
Hi,
I have a schema that validates the following:
<foo:GFF xmlns:foo="http://www.foo.org/foo" foo:articleName=""
foo:id="" foo:namespace=""/>
What should i do so that only the following is...
|
by: ciaran.mchale |
last post by:
Hi folks,
I downloaded the binary version of Xerces C++ 2.7.0 for Windows and am
using it to help me get up to speed with XML and XML Schema. So please
excuse me if this is a "novice" question....
|
by: mrc-1 |
last post by:
Hello,
I built a XSD File with the tool XML-Spy from Altova. My XML file
consists of about 5000 elements. If I use the validate button in
XML-Spy, the validation process takes about 8 seconds....
|
by: Nuno |
last post by:
Hello,
I'm looking for a way of validating/parsing the xsd file (schema), i
only been able of validating the xml file with the corresponding
schema, but what i want is only validate the xsd...
|
by: mstilli |
last post by:
Hi,
I am trying to use schema for server side validation using xerces to
catch the validation errors.
validating this XML:
<Content4>
<textarea13></textarea13>...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |