[xsd-users] question on optional elements/attributes syntax
Ballentine, Casey
crballentine at essvote.com
Fri Nov 13 09:55:52 EST 2015
Hello,
I've recently upgraded to XSD 4.0.0 from 3.1.0 and I've noticed that the cxx-tree syntax for optional elements/attributes changed. For instance, a required element/attribute would have this call syntax:
MyElementType myElement = myXmlDataPointer->ThisIsMyElement();
Whereas optional elements/attributes needed this syntax:
if (myXmlDataPointer->ThisIsMyElement().present())
{
myElement = myXmlDataPointer->ThisIsMyElement().get();
}
else
{
myElement = DEFAULT_VALUE;
}
So basically an optional element/attribute didn't have the ThisIsMyElement() direct access method. I found this handy in that if we changed an element from required to optional I could follow the resulting compiler errors and verify that myElement was getting set to a proper default value.
Did this really change from XSD 3.1.0 or am I dense? And is there a way to prevent an optional object from generating a ThisIsMyElement() direct access method?
C++ compiler: g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4 (in case that's relevant).
Thanks,
Casey
More information about the xsd-users
mailing list