473,385 Members | 1,707 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,385 software developers and data experts.

Xerces-C SAX2 loadGrammar DTD

Hello,

I want to load a grammar which doesnt not come with a DOCTYPE
declaration,

I tried with those lines, and it doesn't work

parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, false)

// Load grammar and cache it
parser->loadGrammar(/path/to/my/file.dtd", Grammar::DTDGrammarType,
true);
// enable grammar reuse
parser->setFeature(XMLUni::fgXercesUseCachedGrammarInPars e, true);

Actually, If the <! DOCTYPE validation SYSTEM "file.dtd" > declaration
is present, it does the validation with the file in the current path,
not the one I loaded in cache.
if the <! DOCTYPE ... > is not there, it does not validate.

for example, it would be nice if it were possible to override a DOCTYPE
declaration

Thank You,
Delphin

May 24 '06 #1
2 2500
Hi Delphin,

de************@gmail.com writes:
Hello,

I want to load a grammar which doesnt not come with a DOCTYPE
declaration,

I tried with those lines, and it doesn't work

parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, false)
What happens if you also add these?

parser->setFeature(XMLUni::fgXercesDynamic, false);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);


// Load grammar and cache it
parser->loadGrammar(/path/to/my/file.dtd", Grammar::DTDGrammarType, true);
// enable grammar reuse
parser->setFeature(XMLUni::fgXercesUseCachedGrammarInPars e, true);

Actually, If the <! DOCTYPE validation SYSTEM "file.dtd" > declaration
is present, it does the validation with the file in the current path,
not the one I loaded in cache.
if the <! DOCTYPE ... > is not there, it does not validate.

for example, it would be nice if it were possible to override a DOCTYPE
declaration


My understanding is that the loadGrammar works as a proxy to entity
resolver. In other words, when the parser sees

<! DOCTYPE validation SYSTEM "file.dtd" >

it normally calls entity resolver to locate file.dtd but before that it
consults the grammar cache to see if this grammar was already loaded.
So I think the reason why if does not work is because without the
above DOCTYPE there is nothing in the document that specifies against
which schema we should validate (note that nothing prevents you from
caching several unrelated schemas). In case of XML Schema, there is
the fgXercesSchemaExternalSchemaLocation property that allows you
to specify schemas for namespaces and thus trigger validation if
a document refers to one of those namespaces. In case of DTD, I don't
see any similar mechanism. You may also find the following article
interesting:

http://www-128.ibm.com/developerwork...x-xsdxerc.html

hth,
-boris

--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding
May 25 '06 #2
Hi Boris!

My understanding is that the loadGrammar works as a proxy to entity
resolver. In other words, when the parser sees

<! DOCTYPE validation SYSTEM "file.dtd" >
it normally calls entity resolver to locate file.dtd but before that it
consults the grammar cache to see if this grammar was already loaded.
So I think the reason why if does not work is because without the
above DOCTYPE there is nothing in the document that specifies against
which schema we should validate (note that nothing prevents you from
caching several unrelated schemas). In case of XML Schema, there is
the fgXercesSchemaExternalSchemaLocation property that allows you
to specify schemas for namespaces and thus trigger validation if
a document refers to one of those namespaces. In case of DTD, I don't
see any similar mechanism. You may also find the following article
interesting: http://www-128.ibm.com/developerwork...x-xsdxerc.html hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding


Thank you for your help, the article was interesting, but I wanted to
use DTD rather XSD because it is more simple and it is sufficient for
my project.
I finaly choosed to pass the DTD file name in the XML file this way :

<! DOCTYPE rootElement SYSTEM "relativeFileName.dtd" >

I have overloaded MyHandler::resolveEntity to return a
LocalFileInputSource using the application specific basePath and the
relativeFileName given in the XML Document.

//dtdPath is a member of MySAX2Handler that I init before to parse
void MySAX2Handler::setDTDPath(const char* dtdPath_) { dtdPath =
dtdPath_;}

InputSource* MySAX2Handler::resolveEntity(
const XMLCh *const publicId, const XMLCh *const systemId) {
XMLCh* transcoded = XMLString::transcode(dtdPath);
InputSource* inSrc = new LocalFileInputSource(transcoded,
systemId,
XMLPlatformUtils::fgMemoryManager);
XMLString::release(&transcoded);
return inSrc;
}

This way it works, but it does not seem to be the perfect solution.

Delphin

May 26 '06 #3

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

Similar topics

2
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...
1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
0
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...
0
by: Jim Phelps | last post by:
After having memory leak issues with Xerces-c 2.3.0 for Solaris 2.7 for CC 6.2 I have decided to update to at least 2.4. I have downloaded the binary tarball and have installed it on my...
0
by: Dale Gerdemann | last post by:
I've been trying to use DOM level 3 with xerces-2_6_2. There's a sample called samples/DOM3.java, but I've had trouble with compilation. I've downloaded Xerces-J-bin.2.6.2 and...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
3
by: Matt | last post by:
Hello, Summary: Where can one download a Xerces-C (XML pardser) dynamic library file (.DLL file) for Windows (Win98/WinNT/Win2k/WinXP/Win2003, including server flavors; don't need to support...
2
by: Vlad Zorinov | last post by:
I'm getting the following error after a couple of months of XML processing, using Xerces 2.0.0 in an apache tomcat. Does anyone have any ideas what this problem may be or what I should do to solve...
3
by: Raphael Tagliani | last post by:
(english version below) Bonjour! Je travaille sur un gros projet java, qui parse beaucoup de fichiers xml au lancement d'un serveur. Nous avons un problème de concurrence qu lancement. En...
9
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>...
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: 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...
0
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...
0
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
0
BarryA
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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.