You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by David Webber <da...@musical.demon.co.uk> on 2010/01/01 11:53:01 UTC
Using a local DTD
Hi,
I am new to Xerces but have successfully got a DOMLSParser to work in C++ -
in as far as I can load a document and find its nodes.
However the
parseURI( pszFilename );
takes forever (over a minute) validating according to a DOCTYPE statement of
the form:
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0
Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
I want to replace the reference to the DTD by a reference to a copy on my
machine when calling parseURI( ).
It looks to me like I need to use the DOMLSResourseResolver and DOMLSInput
classes but the documentation requires a level of knowledge and
understanding which I do not have.
Is there any sample code anywhere showing exactly how to do this?
Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Re: Using a local DTD
Posted by David Webber <da...@musical.demon.co.uk>.
From: "David Bertoni" <db...@apache.org>
>>...
>> I want to replace the reference to the DTD by a reference to a copy on my
>> machine when calling parseURI( ).
>>...
> It's pretty straightforward: ...
Thanks for this. It works brilliantly.
Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
RE: XMLCh class
Posted by John Lilley <jl...@datalever.com>.
In my experience that is true. We were able to get away with it before moving to Linux.
john
-----Original Message-----
From: David Webber [mailto:dave@musical.demon.co.uk]
Sent: Tuesday, January 05, 2010 11:49 AM
To: c-users@xerces.apache.org
Subject: XMLCh class
Am I right in thinking that in a program purely for a Windows XML/Vista/7
platform, which uses all character strings in the native UTF-16 format, I
can interchange XMLCh and wchar_t with no worries?
For example
XMLCh string[] = L"This is a standard unicode string";
And then when a Xerces API function requires an argument of type const
XMLCh * , I can just pass it this string?
In other words are all the XMLString routines just there to give platform
independence (in particular on platforms for which UTF-16 is not native)?
The reason I ask is that it would be nice to be able to use the c runtime
library for string manipulation and/or MFC and STL string classes. (I have
no intention of going beyond the Windows environment.)
Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Re: XMLCh class
Posted by David Webber <da...@musical.demon.co.uk>.
From: "David Bertoni" <db...@apache.org>
>> XMLCh string[] = L"This is a standard unicode string";
> Yes, on Windows, XMLCh is a typedef for wchar_t. It's not a class on any
> platform.
>...
Thanks.
> Then you should be fine, but you might want to be consistent and use XMLCh
> and XMLString everywhere, just in case.
Yes - I like to be consistent too. I would always pass an XMLCh * (rather
than a wchar_t *) to a function which had that as a parameter, but in
particular for example
const XMLCh myString[] = L"This is my string";
seems to be a much simpler way to define a constant UTF-16 string than using
XMLString::transcode() and then having to free the memory later [and,
though I can guess, I don't really understand 100% what it's doing].
Anyway thanks again for your assistance, I'm feeling I'm starting to get to
know Xerces a bit now. [Enough that I've given up on MSXML!]
Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Re: XMLCh class
Posted by David Bertoni <db...@apache.org>.
On 1/5/2010 10:49 AM, David Webber wrote:
> Am I right in thinking that in a program purely for a Windows
> XML/Vista/7 platform, which uses all character strings in the native
> UTF-16 format, I can interchange XMLCh and wchar_t with no worries?
> For example
>
> XMLCh string[] = L"This is a standard unicode string";
Yes, on Windows, XMLCh is a typedef for wchar_t. It's not a class on any
platform.
>
> And then when a Xerces API function requires an argument of type const
> XMLCh * , I can just pass it this string?
>
> In other words are all the XMLString routines just there to give
> platform independence (in particular on platforms for which UTF-16 is
> not native)?
For many of the functions, that's the case. But there are XMLString
functions that have no analog in the ANSI C or C++ libraries.
>
> The reason I ask is that it would be nice to be able to use the c
> runtime library for string manipulation and/or MFC and STL string
> classes. (I have no intention of going beyond the Windows environment.)
Then you should be fine, but you might want to be consistent and use
XMLCh and XMLString everywhere, just in case.
Dave
XMLCh class
Posted by David Webber <da...@musical.demon.co.uk>.
Am I right in thinking that in a program purely for a Windows XML/Vista/7
platform, which uses all character strings in the native UTF-16 format, I
can interchange XMLCh and wchar_t with no worries?
For example
XMLCh string[] = L"This is a standard unicode string";
And then when a Xerces API function requires an argument of type const
XMLCh * , I can just pass it this string?
In other words are all the XMLString routines just there to give platform
independence (in particular on platforms for which UTF-16 is not native)?
The reason I ask is that it would be nice to be able to use the c runtime
library for string manipulation and/or MFC and STL string classes. (I have
no intention of going beyond the Windows environment.)
Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Re: Using a local DTD
Posted by David Bertoni <db...@apache.org>.
On 1/1/2010 2:53 AM, David Webber wrote:
> Hi,
>
> I am new to Xerces but have successfully got a DOMLSParser to work in C++ -
> in as far as I can load a document and find its nodes.
>
> However the
>
> parseURI( pszFilename );
>
> takes forever (over a minute) validating according to a DOCTYPE
> statement of
> the form:
>
> <!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0
> Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
>
> I want to replace the reference to the DTD by a reference to a copy on my
> machine when calling parseURI( ).
>
> It looks to me like I need to use the DOMLSResourseResolver and DOMLSInput
> classes but the documentation requires a level of knowledge and
> understanding which I do not have.
>
> Is there any sample code anywhere showing exactly how to do this?
It's pretty straightforward:
1. Derive your own class from DOMLSResourceResolver and implement the
resolveResource() function. The implementation should just compare the
public ID parameter with the public ID of the DTD you want to load locally:
#include "xercesc/dom/DOMLSResourceResolver.h"
#include "xercesc/util/XMLString.h"
#include "xercesc/framework/Wrapper4InputSource.hpp"
#include "xercesc/framework/LocalFileInputSource.hpp"
class myResolver : public DOMLSResourceResolver {
public:
myResolver();
virtual ~myResolver();
virtual DOMLSInput* resolveResource(const XMLCh* const resourceType
, const XMLCh* const namespaceUri
, const XMLCh* const publicId
, const XMLCh* const systemId
, const XMLCh* const baseURI);
private:
const XMLCh* m_publicID;
const char* m_fileName;
};
myResolver::myResolver()
: m_publicID(XMLString::transcode("-//Recordare//DTD MusicXML 1.0
Partwise//EN")),
m_fileName("/home/dbertoni/dtds/partwise.dtd") {
}
myResolver::~myResolver() {
XMLString::release(&m_publicID);
}
DOMLSInput* myResolver::resolveResource(const XMLCh* const resourceType
, const XMLCh* const
namespaceUri
, const XMLCh* const publicId
, const XMLCh* const systemId
, const XMLCh* const baseURI) {
if (!XMLString::compareString(m_publicId, publicId)) {
return new Wrapper4InputSource(new LocalFileInputSource(m_fileName));
} else {
return 0;
}
}
2. Install your resolver into the parser:
myResolver resolver;
const XMLCh* parameter = XMLString::transcode("resource-resolver");
parser->getDomConfig()->setParameter(parameter, &resolver);
XMLString::release(¶meter);
Dave