[xsd-users] Malformed document

Matthias Röhser roehser at surgitaix.com
Wed Aug 12 08:02:06 EDT 2015


Hi Boris,

 

I ran into a very strange issue with xsd, that produces malformed xml
documents. The original schema is very complex, so I prepared a very minimal
example. Changing the name of the only element in my schema from "GetMDIB"
to "GetMdib" triggers the error. These are used as root elements in an
otherwise empty xml document. I get the same behaviour with a slightly more
complex schema, when the element actually contains content. I also found a
workaround. See the details below.

 

I'm very confused right now. Do I miss something important here? 

Thank you for your help. Do you need any more information?

 

Kind regards

 

Matthias

 

 

System configuration:

Standard Ubuntu 15.04, xsd 4.0.0 from the repository, xerces-c 3.1 from the
repository, gcc 4.9.2 from the repository.

 

Schema files used: (Please note the difference in the name of the element)

 

A.xsd

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

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msg="http://message-model-uri/15/04"
targetNamespace="http://message-model-uri/15/04"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xml:lang="en" >

               <xsd:element name="GetMDIB">

                              <xsd:complexType>

                              </xsd:complexType>

               </xsd:element>

</xsd:schema>

 

B.xsd

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

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msg="http://message-model-uri/15/04"
targetNamespace="http://message-model-uri/15/04"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xml:lang="en" >

               <xsd:element name="GetMdib">

                              <xsd:complexType>

                              </xsd:complexType>

               </xsd:element>

</xsd:schema>

 

I compiled them independently to different C++ target namespaces with xsdcxx
using the following command lines:

xsdcxx cxx-tree --show-sloc --type-naming ucc --generate-polymorphic
--polymorphic-type-all --generate-forward --generate-serialization
--hxx-suffix ".hxx" --cxx-suffix ".cxx" --ixx-suffix ".ixx" --namespace-map
http://message-model-uri/15/04=CDMA  --std c++11 A.xsd

xsdcxx cxx-tree --show-sloc --type-naming ucc --generate-polymorphic
--polymorphic-type-all --generate-forward --generate-serialization
--hxx-suffix ".hxx" --cxx-suffix ".cxx" --ixx-suffix ".ixx" --namespace-map
http://message-model-uri/15/04=CDMB  --std c++11 B.xsd

 

My driver implementation is:

 

#include <iostream>

#include <sstream>

 

#include "A.hxx"

#include "B.hxx"

 

const std::string NS("http://message-model-uri/15/04");

const std::string ENCODING("UTF-8");

 

int main() {

               {             // use CDMA::GetMDIB, behaves correctly

                              const CDMA::GetMDIB requestA;

                              {

                                            std::ostringstream result;

                                            xml_schema::NamespaceInfomap
map;

                                            CDMA::GetMDIB_(result, requestA,
map, ENCODING);

                                            std::cout << result.str() <<
std::endl;

                              }

                              {

                                            std::ostringstream result;

                                            xml_schema::NamespaceInfomap
map;

                                            map["p1"].name = NS;

                                            CDMA::GetMDIB_(result, requestA,
map, ENCODING);

                                            std::cout << result.str() <<
std::endl;

                              }

                              {

                                            std::ostringstream result;

                                            xml_schema::NamespaceInfomap
map;

                                            map["msg"].name = NS;

                                            CDMA::GetMDIB_(result, requestA,
map, ENCODING);

                                            std::cout << result.str() <<
std::endl;

                              }

               }

 

    {         // use CDMB::GetMdib, has errors

        const CDMB::GetMdib requestB;

                              {             // has invalid namespace prefix

                                            std::ostringstream result;

                                            xml_schema::NamespaceInfomap
map;

                                            CDMB::GetMdib_(result, requestB,
map, ENCODING);

                                            std::cout << result.str() <<
std::endl;

                              }

                              {             // has invalid namespace prefix

                                            std::ostringstream result;

                                            xml_schema::NamespaceInfomap
map;

                                             map["p1"].name = NS;

                                            CDMB::GetMdib_(result, requestB,
map, ENCODING);

                                            std::cout << result.str() <<
std::endl;

                              }

                              {

                                            std::ostringstream result;

                                            xml_schema::NamespaceInfomap
map;

                                            map["msg"].name = NS;

                                            CDMB::GetMdib_(result, requestB,
map, ENCODING);

                                            std::cout << result.str() <<
std::endl;

                              }

    }

 

    return 0;

}

 

This implementation produces the following output, where blocks 4 and 5 are
malformed:

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<p1:GetMDIB xmlns:p1="http://message-model-uri/15/04"/>

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<p1:GetMDIB xmlns:p1="http://message-model-uri/15/04"/>

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<msg:GetMDIB xmlns:msg="http://message-model-uri/15/04"/>

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<p1:GetMdib xmlns:p1:GetMdib="http://message-model-uri/15/04"/>

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<p1:GetMdib xmlns:p1:GetMdib="http://message-model-uri/15/04"
xmlns:p1="http://message-model-uri/15/04"/>

 

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<msg:GetMdib xmlns:msg="http://message-model-uri/15/04"/>

 

I have all source files in a default eclipse CDT (Mars) hello world project
with standard compilation settings. The only change is linking against
xerces-c.

 

--------------------

 

Dipl.-Math. Matthias Röhser

Softwareentwicklung

 

SurgiTAIX AG, TPH 1, 2. Etage

Kaiserstraße 100

D-52134 Herzogenrath

 

Mail: roehser at surgitaix.de

I-Net: www.surgitaix.de

Tel: +49 2407 555-999-0

Fax: +49 2407 555-999-1

 

Vorstand:

Dr. Frank Portheine

Vorsitzender Aufsichtsrat:

Dr. Stephan Erbse

 

Amtsgericht Aachen HRB 8474

UStIdNr. DE 215423410

 



More information about the xsd-users mailing list