How to create XSD without repeating myself
-
I want to create an XSD schema that describes this XML:
<report>
<head showpagenumer="true">
<line left="10" top="100" width="200" />
<image left="10" top="100" path="logotype.jpg" />
<text size="16" value="This is the header" />
</head><body leftmargin="20">
<line left="50" top="200" width="200" />
<image left="15" top="300" path="diagram.jpg" />
<text size="12" value="Here is the diagram" />
</body><foot showdate="true">
<line left="10" top="600" width="200" />
<image left="10" top="650" path="signature.jpg" />
<text size="12" value="This is the footer" />
</foot>
</report>Note the following: - I dont want to repeat the line, image and text descriptions three times in the XSD, since they will always be se same format in the head, body and foot nodes. - As you can see, the allowed attributes in the head, body and foot nodes are different Is it possible to create an XSD like this?
-
I want to create an XSD schema that describes this XML:
<report>
<head showpagenumer="true">
<line left="10" top="100" width="200" />
<image left="10" top="100" path="logotype.jpg" />
<text size="16" value="This is the header" />
</head><body leftmargin="20">
<line left="50" top="200" width="200" />
<image left="15" top="300" path="diagram.jpg" />
<text size="12" value="Here is the diagram" />
</body><foot showdate="true">
<line left="10" top="600" width="200" />
<image left="10" top="650" path="signature.jpg" />
<text size="12" value="This is the footer" />
</foot>
</report>Note the following: - I dont want to repeat the line, image and text descriptions three times in the XSD, since they will always be se same format in the head, body and foot nodes. - As you can see, the allowed attributes in the head, body and foot nodes are different Is it possible to create an XSD like this?
I guess you can do something like this: First create your own type.
Then use it for your elements, head, body and foot
-
I want to create an XSD schema that describes this XML:
<report>
<head showpagenumer="true">
<line left="10" top="100" width="200" />
<image left="10" top="100" path="logotype.jpg" />
<text size="16" value="This is the header" />
</head><body leftmargin="20">
<line left="50" top="200" width="200" />
<image left="15" top="300" path="diagram.jpg" />
<text size="12" value="Here is the diagram" />
</body><foot showdate="true">
<line left="10" top="600" width="200" />
<image left="10" top="650" path="signature.jpg" />
<text size="12" value="This is the footer" />
</foot>
</report>Note the following: - I dont want to repeat the line, image and text descriptions three times in the XSD, since they will always be se same format in the head, body and foot nodes. - As you can see, the allowed attributes in the head, body and foot nodes are different Is it possible to create an XSD like this?
By the way, Visual Studio (version 2015, but perhaps also others) can do that job for you: open the xml file in the editor, and then click on the "Create Schema" icon in the toolbar.