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 "Clausen Peter M." <pe...@fe-design.de> on 2006/08/31 11:13:31 UTC

XML as input file format

Hello

I am not sure if this is the right forum, but any help will be highly appreciated.

I am a developer at a software company where we are considering XML as input file format. XML and Schema posibilities seems perfect for our use, where we have some simple user data we have to process and store, using C++ routines. An important aspect, though, is that if there is an error in the input file(s), a good error message must be given to the user. 

Unfortunately, I am new to XML and Xerces. I cannot force the parser to give good errors. Please look at this example - my input file is not going to be much more complicated (just longer with more elements)!!!

<inp_file>
<group name="some_group">
  <item_value>my_group</item_value>
</group>
<dv id_name="var">
    <group_link>some_group</group_link>
</dv>
<command id_name="opt">
    <dv_link>var</dv_link> 
</command >
</inp_file>

The "opt" is linked to "var" which is linked to "some_group". Some part of my schema is:
<xs:element name="parfile">
...
   <xs:key name='dv_id'>
        <xs:selector xpath="dv"/>
        <xs:field xpath="@id_name"/>
    </xs:key>
    <xs:keyref name="opt_ref" refer='dv_id'>
        <xs:selector xpath="command"/> 
        <xs:field xpath="dv_link"/>  
    </xs:keyref>
</xs:element>

Now, this works wonderful when everything is all right. But our typical user will often tip something in the input file by hand and very possibly make a type-o, ie. <dv id_name="var1"> . Using the simple examples in Xerces, fx DOMPrint I get following error:
>>
Error at file "p1.xml", line 24, column 11
   Message: The key for identity constraint of element 'inp_file' is not found.
>>
This error simply tells me "something is wrong with the root object"! But somewhere the parser must check if the referenced 'command -> dv_link -> "var" ' exists. Maybe I have understood XML/Xpath wrong, but the error message I was looking for was something like:
>>
'command -> dv_link -> var' is referenced, but not defined
'dv -> var1' is never referenced
>>

Now the question: Is it possible to force this kind of errors out of Xerces? 

In advance, thank you, at least that you have read this far... :-) 

Best regards 

Peter