问题
Not all that familiar with XSD, I wonder if it is possible to do the following:
<xs:group name="SomeGroup">
<xs:sequence>
<xs:element name="Groupingcode" type="OurType" origin="DB" />
<xs:element name="Description" type="StringType" origin="XML" />
To explain: I have an XSD schema file. I need to generate an XML file according to the XSD (this part works fine) containing database data. However, some elements need additional data to be able to find the proper field to get from the database. That's where the origin tag would come in. It would allow me to describe in the XSD where to look for the data. The tag need not be present in the generated XML, but if possible that same XSD would be used to validate the generated XML. Another way would be to use a separate XML file to describe this, I know. But I would like to know if it would at all be possible to do this in my XSD.
The above fragment would generate to the following XML:
<SomeGroup>
<Groupingcode>None</Groupingcode>
<Description>This item does not belong to any group.</Description>
Hope this makes sense.
回答1:
Go right ahead. Just put your extra attributes into a namespace of your own, and create a schema that defines them. Microsoft does this for the .XSD files generated when you create a DataSet.
来源:https://stackoverflow.com/questions/633969/add-metadata-to-an-xsd-definition