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 Ma...@VerizonWireless.com on 2005/06/06 18:30:23 UTC

RE: Unable to set an external schema

You must first change that schema name string to UTF-16.
Try the following trivial C++ function:

// widen function
// Converts ASCII std::string to XMLCh array.
// NOTE: Caller must delete XMLCh array when finished with it.
XMLCh* widen(const string& src)
{
    // Allocate buffer.
    XMLCh* dest = new XMLCh[src.length() + 1];

    // Copy from string to buffer.
    string::size_type i;
    for (i=0; i < src.length(); ++i)
        dest[i]=(XMLCh)src[i];

    // Add NULL byte.
    // WARNING: Not index [i+1] as this code was before.
    dest[i]=0;

    // Return const pointer to array.
    return dest;
}

-----Original Message-----
From: Bart Friederichs [mailto:bf@tbwb.nl]
Sent: Monday, June 06, 2005 5:55 AM
To: c-users@xerces.apache.org
Subject: Unable to set an external schema



Hi all,

I want to validate an XML file to a schema, but the XML file doesn't 
have a reference to that schema. I want to use the setProperty function 
of the DOMBuilder to set an external schema, without namespaces, but 
this doesn't seem to work.

Here is the (head of the) XML file I want to validate:
<JobqueueXML>
        <MessageNumber>2483920</MessageNumber>
...

This is the (head of the) XMLSchema:
<xs:schema
        attributeFormDefault="unqualified"
        elementFormDefault="qualified" 
xmlns:xs="http://www.w3.org/2001/XMLSchema">


  <xs:element name="JobqueueXML">
...

The Schema definition is correct and when I reference the Schema in the 
XML file, it gets validated, but the files I get (I do not produce them 
myself) do not have the reference in it, so I want to set it this way:
    parser->setProperty (XMLUni::
                 fgXercesSchemaExternalNoNameSpaceSchemaLocation,
                 "job.xsd");

Where 'job.xsd' is the Schema file. 'parser' is a DOMBuilder object, as 
defined in the DOMCount sample program (I used that as reference). 
However, this does not work. There is no validation at all, even if I 
change the name into something unresolvable (e.g. a non-existing file) 
it gives no error.

Could someone give me some help on how to fix this?

TIA
Bart Friederichs
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.