Reusing XML objects
January 17, 2008 6:11 PM
Subscribe
Can I somehow reuse elements in an XML doc (e.g. - like the way you can use a ref tag to resuse elements in an XML Schema)?
I'm new-ish to XML and this seems like an obvious, simple thing to want to do, but I can't work out how to do it. There are a few element instantiations in my documents that I find myself re-doing over and over again. Is there anyway to define it once and then just refer to that one definition everywhere it needs to occur? You can do this with in a Schema, so it seems like you ought to be able to do it in a doc too... Bonus points if I can also override the values of some of its children.
posted by badstone to computers & internet (3 comments total)
2 users marked this as a favorite
idattribute specifies this identifier. Some XML tools, like an XSLT processor, will give you a way to generate unique identifiers programmatically.The reuse you want really all depends on your XML dialect and your parsing and processing code to understand that when it sees an element with an attribute like, e.g.
ref="#my-generic-stuff"then it should look up a node with the idmy-generic-stuffand make the appropriate substitution.XML itself isn’t really much more than a specification of a syntax; the semantics of the language depend entirely on your tools.
posted by ijoshua at 7:02 PM on January 17, 2008