[xsd-users] Generated XML does not have full schema qualifiers

Wesley Peters Wesley.Peters at tachyon.com
Thu Sep 27 13:22:06 EDT 2012


Hi, I have a pair of simple programs attempting to communicate with each
other using code generated by XSD.  Program A creates a request, sends it to
Program M, and waits for a reply.  Program M receives the request, acts on
it if it's understood, and replies -- basically an RPC.

The problem I have is, when Program A creates the request, the generated XML
is "qualified enough" for Program M to parse it.  First, here's my xsd:

<?xml version="1.0" encoding="utf-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                      xmlns:p="http://schema.tachyon.com/modemCommand"

targetNamespace="http://schema.tachyon.com/modemCommand">

    <!-- types -->
    <xsd:complexType name="registerCondition_t">
        <xsd:sequence>
            <xsd:element name="topic" type="xsd:string" />
            <xsd:element name="interval" type="xsd:unsignedInt" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="configureModem_t">
        <xsd:sequence>
            <xsd:element name="centerFrequencey" type="xsd:float" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="modemResponse_t">
        <xsd:sequence>
            <xsd:element name="success" type="xsd:boolean" />
        </xsd:sequence>
    </xsd:complexType>

    <!-- request elements -->
    <xsd:element name="RegisterCondition" type="p:registerCondition_t"/>
    <xsd:element name="ConfigureModem" type="p:configureModem_t" />

    <!-- response elements -->
    <xsd:element name="ModemResponse" type="p:modemResponse_t" />

</xsd:schema>


Here's the request XML I hand created to test Program M:

    <?xml version="1.0"?>
    <p:RegisterCondition xmlns:p="http://schema.tachyon.com/modemCommand"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://schema.tachyon.com/modemCommand
          modemCommand.xsd">
       <topic>STEP</topic>
       <interval>200</interval>
    </p:RegisterCondition>

Here's the XML my Program A creates from the schema:

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <p:RegisterCondition xmlns:p="http://schema.tachyon.com/modemCommand">
        <topic>STEP</topic>
        <interval>200</interval>
    </p:RegisterCondition>

Attempting to parse this in Program M one results in:

antennaRequest0.xml:2:71 error: no declaration found for element
'p:RegisterCondition'
antennaRequest0.xml:2:71 error: attribute '{http://www.w3.org/2000/xmlns/}p'
is not declared for element 'p:RegisterCondition'
antennaRequest0.xml:4:10 error: no declaration found for element 'topic'
antennaRequest0.xml:6:13 error: no declaration found for element 'interval'

I've edited the output, testing which of the 3 differences (encoding,
standalone, and namesapces) seems to spur the problem, and it's in the lack
of namespace.  If I convert it to:

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <p:RegisterCondition xmlns:p="http://schema.tachyon.com/modemCommand"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://schema.tachyon.com/modemCommand
              modemCommand.xsd">
        <topic>STEP</topic>
        <interval>200</interval>
    </p:RegisterCondition>

Program M understands this document just fine:

RegisterCondition: STEP @ 200 msec

Here's the snippet from Program A where the "command" document is created,
this is lifted straight from the Messaging driver program in the examples:

        std::auto_ptr<xml_schema::element_type> req, res;
        modemCommand::registerCondition_t rc("STEP", 200);
        req.reset(new modemCommand::RegisterCondition(rc));

        // Serialize the request to a DOM document.

        const XMLCh ls_id[] =
        {
            xercesc::chLatin_L,
            xercesc::chLatin_S,
            xercesc::chNull
        };
        xercesc::DOMImplementation*
impl(xercesc::DOMImplementationRegistry::getDOMImplementation(ls_id));

        const std::string & name(req->_name());
        const std::string & ns(req->_namespace());

        xml_schema::dom::auto_ptr<xercesc::DOMDocument>
doc(impl->createDocument(xsd::cxx::xml::string(ns).c_str(),

xsd::cxx::xml::string("p:" + name).c_str(),

0));
        doc->setXmlStandalone(true);

        xml_schema::element_map::serialize(*doc->getDocumentElement(),
*req);

Breaking on the line where the document is created, we see:

Breakpoint 1, main (argc=1, argv=0x7fff5fbff818) at antenna.cxx:60
60                                                                 0));
(gdb) p name.c_str()
$1 = 0x100506418 "RegisterCondition"
(gdb) p ns.c_str()
$2 = 0x1005061d8 "http://schema.tachyon.com/modemCommand"

As expected, the namespaceURI is "http://schema.tachyon.com/modemCommand"
and the qualifiedName is "p:RegisterCondition".  My question is, how do I
add the additional namespace URIs to the document?  Can the full list of
namespace URIs be fetched from the XSD somehow?  I assume the _name and
_namespace in "req" come from my modemCommand::RegisterCondition object,
which was created from the XSD, but the path to the additional namespaces
isn't obvious from the examples or the doco I've seen so far.

Thanks for any help you can offer.

Wes Peters



Confidentiality Notice:  The information contained in this electronic e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and is confidential and/or privileged. If you and we have a confidentiality agreement or other non-disclosure obligations between us, this Notice shall be deemed to mark and identify the content of this email and any attachments as confidential and proprietary.   If any reader of this communication is not the intended recipient, unauthorized use, disclosure or copying is strictly prohibited, and may be unlawful.  If you have received this communication in error, please immediately notify the sender by return e-mail, and delete the original message and all copies from your system.  Thank you.

IRS Circular 230 Disclosure: To ensure compliance with requirements imposed by the IRS, please be advised that any U.S. federal tax advice contained in this communication (including any attachments) is not intended or written to be used or relied upon, and cannot be used or relied upon, for the purpose of (i) avoiding penalties under the Internal Revenue Code, or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.

E-mail is susceptible to data corruption, interception, unauthorized amendment, tampering and viruses, and we only send and receive e-mails on the basis that we are not liable for any such corruption, interception, amendment, tampering or viruses or any consequences thereof.




More information about the xsd-users mailing list