tags:

views:

24

answers:

3

I have been tasked with writing an xsd, for an xml file format that my company has created.

Unfortunately one of the tags contains two variables, here is an example of the tag

<to_1.1.1.0_24>

The 1.1.1.0 is an ip address and as such can change, and the 24 is the netmask. Is there anyway of expressing this within an xsd document.

Many Thanks

David

A: 

No. And in general this is very bad form for an XML document as it makes parsing it considerably less straightforward than it ought to be. Really it should be something like

<to network="1.1.1.0" netmask-bit="24">...</to>

or something like that

dty
+3  A: 

No.

The tag itself shouldn't contain variable data. That should be split out into either attributes or elements. For example:

<to ip="1.1.1.0" netmask="24" />

or:

<to>
    <ip>1.1.1.0</ip>
    <netmask>24</netmask>
</to>
Justin Niessner
Thank you, I was hoping this wasn't the case. This is what I suspected as the decoding of the xml, is quite complex. Unfortunatly I didn't design this part of the software or xml structure.
David Ashmore
A: 

Use the xsd:any element. That will validate this kind of element.

However, it won't fail validation for anything else, but that's the kind of tradeoff you have to make when you crowbar this sort of thing into XML.

Paul Butcher