[xsd-users] Assignment of optional boolean attribute does not
survive on the heap; possibly a bug?
Andreas.Hackeloeer at bmw.de
Andreas.Hackeloeer at bmw.de
Wed Jun 26 07:07:46 EDT 2013
Hi,
I am encountering the following problem:
I have this schema:
<xs:schema ..>
<xs:element name="Configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="MapManager" type="MapManagerType" maxOccurs="1" minOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="MapManagerType">
<xs:sequence>
<xs:element name="Map" type="MapType" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="MapType">
<xs:attribute name="Title" type="xs:string" use="required" />
<xs:attribute name="SelectedSourceMap" type="xs:boolean" use="optional" />
</xs:complexType>
</xs:schema>
An XML file according to this schema might look like this:
<Configuration>
<MapManager>
<Map Title="MyMap" SelectedSourceMap="true" />
</MapManager>
</Configuration>
I have no problems loading this XML file. I can enumerate and modify the Map element using this code:
std::tr1::shared_ptr<Configuration> myConfig = configuration("test.xml");
MapManagerType& myMapManager = myConfig->mapManager();
MapManagerType::MapSequence& myMapSequence = myMapManager.map();
for (MapManagerType::MapIterator i (myMapSequence.begin()); i != myMapSequence.end(); i++)
{
MapType& myMap(*i);
myMap.title("New Title"); // works, Title attribute keeps its new value
myMap.selectedSourceMap(true); // does not work
bool problem = myMap.selectedSourceMap(); // true only as long as the method is being executed
}
The strange thing: Assigning a new string to the Title attribute works, however, assigning a boolean value to the optional boolean attribute SelectedSourceMap does not work. More precisely: The SelectedSourceMap attribute gets assigned the new value, however, after the scope of the method is left, the attribute is reset to false, while the Title attribute keeps its new value. I am accessing the model using a shared_ptr<Configuration> class member variable.
Does anyone have a clue what might be causing the problem? I would greatly appreciate any help!
Best regards,
Andreas Hackeloeer
More information about the xsd-users
mailing list