[xsd-users] Pointers to references
Mathew Benson
mathew.benson at gmail.com
Fri Feb 28 21:16:00 EST 2014
Thanks for the tip. I dug into it more and found that it was much easier
to just change the xsd file a bit to enforce the relationship, while still
keeping the basic schema the same and without writing any code. I know the
relationship is now enforced because if I set a IDREF without an ID, it
will fail to unmarshall the xml file. However, I'm still struggling at how
to get to the object from inside code. Below is a snippet of my input xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<xtce:SpaceSystem name="n/a" xmlns:xtce="http://www.omg.org/space/xtce"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.omg.org/space/xtce SpaceSystemV1.1.xsd">
<xtce:LongDescription>Long description for the header. All long
descriptions work this way.</xtce:LongDescription>
<xtce:Header validationStatus="Draft" classification="Restricted"
date="2008-03-09" version="0.9.1">
</xtce:Header>
<xtce:CommandMetaData>
<xtce:ArgumentTypeSet>
<xtce:StringArgumentType name="IpAddressType" initialValue="0">
<xtce:UnitSet />
<xtce:IntegerDataEncoding sizeInBits="160" />
</xtce:StringArgumentType>
<xtce:IntegerArgumentType name="UdpPortType">
<xtce:UnitSet />
<xtce:IntegerDataEncoding sizeInBits="16" />
<xtce:ValidRange minInclusive="1" maxInclusive="65535" />
</xtce:IntegerArgumentType>
</xtce:ArgumentTypeSet>
<xtce:MetaCommandSet>
<xtce:MetaCommand name="RCM_EnableOutput">
<xtce:ArgumentList>
<xtce:Argument name="IpAddress"
argumentTypeRef="IpAddressType" />
<xtce:Argument name="UdpPort"
argumentTypeRef="UdpPortType" />
</xtce:ArgumentList>
<xtce:CommandContainer name="RCM_EnableOutputPacket">
<xtce:BinaryEncoding>
<xtce:SizeInBits>
<!-- Size of BaseContainer (248) + Size of
items in EntryList (24) -->
<xtce:FixedValue>272</xtce:FixedValue>
</xtce:SizeInBits>
</xtce:BinaryEncoding>
<xtce:EntryList>
<xtce:ArgumentRefEntry argumentRef="IpAddress">
<xtce:LocationInContainerInBits>
<xtce:FixedValue>0</xtce:FixedValue>
</xtce:LocationInContainerInBits>
</xtce:ArgumentRefEntry>
<xtce:ArgumentRefEntry argumentRef="UdpPort">
<xtce:LocationInContainerInBits>
<xtce:FixedValue>160</xtce:FixedValue>
</xtce:LocationInContainerInBits>
</xtce:ArgumentRefEntry>
</xtce:EntryList>
</xtce:CommandContainer>
</xtce:MetaCommand>
</xtce:MetaCommandSet>
</xtce:CommandMetaData>
</xtce:SpaceSystem>
Could you tell me the best way to retrieve
'argumentTypeRef="IpAddressType"' given I have a pointer/reference to the
'<xtce:MetaCommand name="RCM_EnableOutput">' object? I'm trying to iterate
through all the command objects and enumerate all the contained elements
and properties.
On Fri, Feb 28, 2014 at 10:38 AM, Mathew Benson <mathew.benson at gmail.com>wrote:
> Ok. Thanks. Since I'm using an already documented and standardized
> schema, I'm leery about modifying the schema file. I just wish they would
> have considered that when the schema was defined.
>
>
> On Fri, Feb 28, 2014 at 9:05 AM, Boris Kolpackov <boris at codesynthesis.com>wrote:
>
>> Hi Mathew,
>>
>> Mathew Benson <mathew.benson at gmail.com> writes:
>>
>> > <SomeElement name="Object1"/>
>> > <AnotherElement someElementRef="Object1"/>.
>>
>> If your schema uses xs:ID type for 'name' and xs:IDREF for
>> 'someElementRef', then, yes, XSD will resolve such references
>> for you. See:
>>
>> http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.5.5
>>
>>
>> > Is it generating skeletal code that I can/should modify, or should I
>> > treat it as autocode that can be regenerated and should not be modified
>> > directly?
>>
>> The generated code should not be modified but there is a mechanism
>> for customizing the generated classes. For more information on type
>> customization see the C++/Tree Mapping Customization Guide:
>>
>> http://wiki.codesynthesis.com/Tree/Customization_guide
>>
>> As well as the examples in the examples/cxx/tree/custom/ directory.
>>
>> So if ID/IDREF does not apply (i.e., your schema uses key/keyref),
>> then the next best thing is to customize the generated classes to
>> add the pointers and to initialize them in the parsing constructors.
>>
>> Boris
>>
>
>
More information about the xsd-users
mailing list