[xsde-users] How to config xsde to parse without namespace check / How to gain a better error message

Boris Kolpackov boris at codesynthesis.com
Mon Oct 22 12:04:31 EDT 2007


Hi Bin,

Jiang, Bin (Bin) <binjiang at alcatel-lucent.com> writes:

> Sometimes I need parsing a xml fragment without checking the namespace,
> it there any convenient way to do this?
> I've used XSD 2.1.1 2.3.0, and now xsde 1.1.0, my way is modifiy the xsd
> library files and the generated parser files.

I think there is a more elegant way to accomplish this. The idea is
to override the _start_element (and _start_attribute if necessary)
low-level hook on the root parser and call the original version with
a proper namespace when necessary:

virtual void
_start_element (const xml_schema::ro_string& ns,
                const xml_schema::ro_string& name)
{
  if (need_to_add_namespace)
  {
    xml_schema::ro_string ns ("urn:oma:xml:poc:list-service");
    base::_start_element (ns, name);
  }
  else
  {
    base::_start_element (ns, name);
  }
}

This will work because all events are going through the root
element parser. This can get a bit more complicated if your
vocabulary mixes qualified and unqualified elements. But
normally it is either all qualified or only root element that
is qualified and both of these cases are easy to handle with
this method.

> Another question is when there is an exception, like unexpected element
> or attribute, how to get the namespace and name of the encountered
> element or attribute, I only find there is line/column and text().

The current error propagation architecture makes it costly to pass
this information up to the caller. Because of that we decided not
to provide it. However, we are planning to change the inner workings
of C++/Parser which will also make it fairly cheap to pass extra
error information around and we will add support for names and
namespaces then. Unfortunately, this is not planned for XSD/e 2.0.0
(due in a couple of weeks) and will be implemented in XSD/e 2.1.0
which is scheduled for the end of 2007 - beginning of 2008. How
urgent is this feature for your project?

Boris




More information about the xsde-users mailing list