[xsd-users] generated tree with ambiguous references

Boris Kolpackov boris at codesynthesis.com
Wed May 23 16:27:50 EDT 2012


Hi Jens,

In the future please send such questions to the xsd-users mailing list
instead of to me directly, as discussed in the posting guidelines:

http://www.codesynthesis.com/support/posting-guidelines.xhtml

Jens Rapp <rapp.jens at googlemail.com> writes:

> Hi Boris,
>
> sorry, I had to send via webmail and this is the worst webmailer I know.
>
> I'll try to repeat my problem description..
>
> this is my schema
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema xmlns="http://www.w3.org/2001/XMLSchema"  
> targetNamespace="http://www.example.org/mindmodel"  
> xmlns:tns="http://www.example.org/mindmodel" 
> elementFormDefault="qualified">
>
> <complexType name="mindmodel_t">
> <sequence>
> <element name="action" type="tns:action_t" maxOccurs="unbounded"  
> minOccurs="0"></element>
> </sequence>
> </complexType>
>
> <element name="mindmodel" type="tns:mindmodel_t"></element>
>
> <complexType name="action_t">
> <sequence>
> <element name="object" type="tns:object_t" maxOccurs="unbounded"  
> minOccurs="1"></element>
> </sequence>
> <attribute name="name" type="string"></attribute>
> <attribute name="value" type="int"></attribute>
> </complexType>
>
> <complexType name="object_t">
> <sequence>
> <element name="decorator" type="string" maxOccurs="unbounded"  
> minOccurs="0"></element>
> </sequence>
> <attribute name="name" type="string"></attribute>
> </complexType>
> </schema>

In your schema you have the 'mindmodel' global element which is
translated to the mindmodel() parsing/serialization functions. Your
schema's target namespace (http://www.example.org/mindmodel) is
mapped by default to 'mindmodel' (XSD compiler just takes the path
component from the namespace URI and turns into a C++ namespace).
Because the namespace and the functions inside this namespace have
the same name, they conflict.

The easiest way to fix this is to re-map the namespace to some other
name using the --namespace-map option. For example:

--namespace-map http://www.example.org/mindmodel=mm

If you want to place the generated code in the global namespace
(might be the best option for such a small schema), then you can
write this:

--namespace-map http://www.example.org/mindmodel=

Alternatively, you can change the names of the parsing/serialization
functions (e.g., add the 'parse_' and 'serialize_' prefixes) using
the --parser-regex and --serializer-regex options. See the XSD compiler
command line manual (man pages) for details:

http://www.codesynthesis.com/projects/xsd/documentation/xsd.xhtml

Boris

[The rest of the email follows for context.]

>
> Here's how I generate the classes, calling make generate-source.
>
> GENSRCDIR = src/generated-source
> SCHEMADIR = src/schema
>
> XSD2CXX = /usr/bin/xsdcxx
> XTFLAGS = --output-dir $(GENSRCDIR) --hxx-suffix .h --cxx-suffix .cpp
> XPFLAGS = --output-dir $(GENSRCDIR) --hxx-suffix .h --cxx-suffix .cpp  
> --xml-parser expat
>
> object-list: generate-source
> echo -n "SRC = " >sourcefiles.in
> for i in `find ./src -name *.cpp`; do echo -n " $$i" >> sourcefiles.in; done
> echo "" >>sourcefiles.in
> echo "OBJ = \$$(SRC:%.cpp=%.o)" >>sourcefiles.in
> echo "HDR = \$$(SRC:%.cpp=%.h)" >>sourcefiles.in
>
> generate-source: generate-tree
>
> generate-tree:
> $(XSD2CXX) cxx-tree $(XTFLAGS) $(SCHEMADIR)/*.xsd
>
> generate-parser:
> $(XSD2CXX) cxx-parser $(XPFLAGS) $(SCHEMADIR)/*.xsd
>
> Next is my main function, basically copied from the Getting Started Guide.
>
> my compile (do you need the makefile?) trhows these messages..
>
>
> **** Build of configuration Default for project ai-persistence ****
>
> make all
> rm -rf target/*
> /usr/bin/g++ -Wall -g -c src/generated-source/mind.cpp
> /usr/bin/g++ -Wall -g -c src/cxx/main.cpp
> src/cxx/main.cpp: In function ‘int main(int, char**)’:
> src/cxx/main.cpp:19: error: reference to ‘mindmodel’ is ambiguous
> src/cxx/../generated-source/mind.h:223: error: candidates are: namespace  
> mindmodel { }
> src/cxx/../generated-source/mind.h:553: error:  
> std::auto_ptr<mindmodel::mindmodel_t>  
> mindmodel::mindmodel(xsd::cxx::xml::dom::auto_ptr<xercesc_3_1::DOMDocument>&, 
> xml_schema::flags, const xml_schema::properties&)
>
> [...]



More information about the xsd-users mailing list