[xsd-users] Issue parsing document using namespace declaration with cxx-parser

Wood, Matthew D matthew.d.wood at intel.com
Thu Jul 1 19:59:36 EDT 2010


I'm writing an application that uses cxx-parser to handle documents using the XACML schema (http://docs.oasis-open.org/xacml/2.0/access_control-xacml-2.0-policy-schema-os.xsd). The skeleton was generated to include validation and use Xerces as the parser. Many of the documents I'm receiving have the form:

<Policy xmlns="urn:oasis:names:tc:xacml:2.0:policy:schema:os" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PolicyId="urn:intel:spi:testapp:SimplePolicy1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-overrides">
      <Target/>
      <Rule RuleId="urn:oasis:names:tc:xacml:2.0:example:SimpleRule1" Effect="Permit">
            <Description>Anyone can access anything.</Description>
            <Target/>
      </Rule>
</Policy>

The code that initiates the parse looks like the following:

std::istream& policyXml; // opened elsewhere

xml_schema::document doc_p(
  PolicyType_p,
  "urn:oasis:names:tc:xacml:2.0:policy:schema:os",
  "Policy",
  true );

PolicyType_p.pre();
doc_p.parse( policyXml, xml_schema::flags::dont_validate ); // parser skeletons are built with validation support
std::auto_ptr<MyPolicyObject> policy( PolicyType_p.post_PolicyType() );

When I run the code, it catches a xml_schema::exception with message ":2:256 error: unexpected attribute 'xmlns'" instead of treating it as the namespace declaration for the elements. I tried hand modifying a message to use a namespace prefix like the following and parsing works as expected.

<cp:Policy xmlns:cp="urn:oasis:names:tc:xacml:2.0:policy:schema:os" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PolicyId="urn:intel:spi:testapp:SimplePolicy1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-overrides">
      <cp:Target/>
      <cp:Rule RuleId="urn:oasis:names:tc:xacml:2.0:example:SimpleRule1" Effect="Permit">
            <cp:Description>Anyone can access anything.</cp:Description>
            <cp:Target/>
      </cp:Rule>
</cp:Policy>

Is there a known workaround for this or am I missing something in the parser setup? I tried using a cxx-tree skeleton to parse the same documents and had no issues with either encoding.

Thanks,
Matt



More information about the xsd-users mailing list