[xsd-users] ID/IDREF and nillable

Boris Kolpackov boris at codesynthesis.com
Wed Feb 9 10:58:43 EST 2011


Hi Giuseppe,

giuseppe ferrari <giuseppe500 at yahoo.it> writes:

> In my xml i have a set of ref and id attributes.
> I read that xerces builds a id/ref cross/reference.

That's correct, though it is at the DOM level.


> My problem is that the id  ref cross reference don't work! may be that 
> i have the class template nullable-type that don't read the ref attribute
> when the nill attribute == true?

Do you mean the ID/IDREF reference support in the object model does not
work? I.e., using the IDREF type to get the referenced object? If that's
the case then yes, if you don't store the ref attribute in the nillable
type wrapper as xml_schema::idref, then the references won't work.

In essence, what you need to do is add a member to complex_nillable_type
of type xml_schema::idref, let's say it is called ref_.

Then, in the parsing constructor, you initialize it like this:

  complex_nillable_type (const xercesc::DOMElement& e,
                         xml_schema::flags f = 0,
                         xml_schema::container* c = 0)
      : B (e, f | xml_schema::flags::base, c),
        nil_ (false),
        ref_ (xml_schema::idref (""), 0, this)
  {

    string ref_str = ...
    ref_ = ref_str;
  }

Then, once the whole document has been parsed, you can try to resolve
the reference. If you try to resolve inside the parsing constructor,
it may fail because the referenced object may not have been parsed
yet.


Boris



More information about the xsd-users mailing list