I've learned XML/XSD piecemeal. I feel like I need to start over at the
beginning sometimes to fill in all of the knowledge holes. Anyone have a
good resource to do this?
In any case, I've attached a file that has two pieces of my code. I can
give you all more if it will help. I'll look at your suggestions. Thanks
for mentioning XML Notepad too. I'll put that utility through it's paces.
Thanks again guys!
On Thu, Jan 10, 2013 at 8:31 AM, Siva Chandran P
<[email protected]>wrote:
> Hi,
>
> I am not sure why you are getting the error at line 7, probably you can
> show us the source of entity resolver and how you are configuring the
> parser.
>
> I see an error with DFCTypes.xsd at line 79 with XML Notepad schema
> validation.
>
> Line 78, Column 18: Type 'subNumType' is not declared, or is not a simple
> type.
> Line 78, Column 18: Namespace '' is not available to be referenced in this
> schema.
>
> Looks like you need to use namespace prefix even for the types that are
> defined just above. Please find the attached corrected xsd.
>
> Thanks & Regards,
> Siva Chandran P
>
>
> On Wed, Jan 9, 2013 at 2:43 AM, Kelly Beard <[email protected]>wrote:
>
>> Thanks. I had to put some things back. Like I said, I'm blaming adding
>> an entityResolver here because thats the only variable I can find.
>>
>>
>> On Tue, Jan 8, 2013 at 2:49 PM, Ben Griffin <[email protected]> wrote:
>>
>>> Can you put a sample of your XML/Xsd files online in a zip file
>>> somewhere, then I can have a look when. I've got a few mins spare..
>>>
>>> -b
>>>
>>>
>>>
>>> On 8 Jan 2013, at 20:31, Kelly Beard <[email protected]> wrote:
>>>
>>> > I had a dream to make an XSD that contains my most commonly used XML
>>> types
>>> > and have them contained in an XSD that I could import into other XSDs
>>> that
>>> > represented by other form types. The namespace I chose for my types
>>> XSD is
>>> > DFCTypes. The other XSD/XML forms would have their own namespaces.
>>> >
>>> > Here's the thing: I think I'm doing everything correctly. I have a
>>> generic
>>> > program that I adapted from one of the Xerces samples. It just reads
>>> in an
>>> > XML document and spits things out based on the events (startDocument,
>>> > endElement, et al). I use it to validate a new XSD and run test XML
>>> > documents through it to see that the parser isn't going to have
>>> problems.
>>> >
>>> > This sample program has one thing not in common with how I set up my
>>> real
>>> > production stuff: an entity resolver set with setEntityResolver(). The
>>> > sample validator program flies through an XML validated with an XSD
>>> that
>>> > does an <xs:import>. In my production stuff however, I get errors like
>>> > these:
>>> >
>>> > Error at file "/home/dfcuser/rfidLog.xsd", line=7, column=36, XML
>>> element=,
>>> > Imported schema 'DFCTypes.xsd' has a different target NameSpace '
>>> > http://www.quikq.com/xsd/rfidLog' from what's declared '
>>> > http://www.quikq.com/DFCTypes'
>>> >
>>> > Error at file "/home/dfcuser/rfidLog.xsd", line=18, column=95, XML
>>> > element=, Schema Representation Constraint: Namespace '
>>> > http://www.quikq.com/DFCTypes' is referenced without <import>
>>> declaration
>>> >
>>> > Error at file "/home/dfcuser/rfidLog.xsd", line=20, column=97, XML
>>> > element=, Schema Representation Constraint: Namespace '
>>> > http://www.quikq.com/DFCTypes' is referenced without <import>
>>> declaration
>>> >
>>> > Error at file "/home/dfcuser/rfidLog.xsd", line=22, column=97, XML
>>> > element=, Schema Representation Constraint: Namespace '
>>> > http://www.quikq.com/DFCTypes' is referenced without <import>
>>> declaration
>>> >
>>> > The first error regarding "line=7" is about the <xs:import> statement
>>> > itself. There's nothing wrong with it, I swear!
>>> >
>>> > <xs:import namespace="http://www.quikq.com/DFCTypes"
>>> > schemaLocation="DFCTypes.xsd" />
>>> >
>>> > That is the namespace I want to use and that is the file that those
>>> types
>>> > are contained in. Works fine on my validator program - squat on
>>> production
>>> > stuff. Notice the error message says that the namespaces in the
>>> target XSD
>>> > don't match - bullcrap!
>>> >
>>> > Is anyone interested in helping me out here? I'm sure the entity
>>> stuff is
>>> > the problem. I don't know why I need an entity resolver. I can post
>>> > whatever code you'd like to see.
>>> >
>>> > Thanks!
>>> >
>>> > --
>>> > Kelly Beard
>>>
>>
>>
>>
>> --
>> Kelly Beard
>>
>
>
--
Kelly Beard
// ===============================
// This comes from a .h file
// ===============================
class RfidLogResolver : public EntityResolver {
public :
InputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId)
{
CStr2XStr path("/home/dfcuser/rfidLog.xsd"); // need to be changed?
if (XMLString::compareString(systemId, path.unicodeForm())) {
return new LocalFileInputSource(path.unicodeForm());
} else {
return 0;
}
}
};
// ===============================
// Some code in a main
// ===============================
/*
Xerces setup
*/
try {
XMLPlatformUtils::Initialize();
parser = XMLReaderFactory::createXMLReader();
// Report all validation errors.
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
// The parser will validate the document only if a grammar is specified.
// (http://xml.org/sax/features/validation must be true).
parser->setFeature(XMLUni::fgXercesDynamic, true);
// Perform Namespace processing.
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
// The parser will treat validation error as fatal and will exit depends on the state of
// http://apache.org/xml/features/continue-after-fatal-error.
//parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true);
parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, false);
// This could cause problems by allowing the parser to continue after finding a validation error. The default is false.
//parser->setFeature(XMLUni::fgXercesContinueAfterFatalError, true);
defaultHandler = new RfidLogHandler();
RfidLogResolver *rfidLogResolver = new RfidLogResolver(); // See above
parser->setContentHandler(defaultHandler);
parser->setErrorHandler(defaultHandler);
parser->setEntityResolver(rfidLogResolver);
}
catch (const XMLException& e) {
char *message = XMLString::transcode(e.getMessage());
CERR << argv[0] << ": XML toolkit initialization error: " << message << endl;
XMLString::release(&message);
exit(-1);
}
catch (exception& e) {
cerr << "Standard exception: " << e.what() << endl;
}
catch (...) {
CERR << "Unexpected Exception \n" ;
exit(-1);
}