views:

115

answers:

1

I've got an XML Schema and an XML instance that is valid to that schema.

This XML instance contains some data.

I'd like to extend the XML instance with further data(my own meta-data per XML element in the XML instance) while keeping it valid to the provided schema.

The real use-case is that I've my own control that gets its data via XML and I'd like to generate a new XML that somehow keeps additional meta-data that is related to the control's serialization.

Couple of my solutions were to keep another document with a list of "XPath,Mode,Color" that I load in the second pass after loading the XML.

Another solution was to add id's to the XML nodes and this way referencing the nodes from another document (instead of using XPath).

And another idea was to somehow add attributes (that are in my namespace per element) to the data XML instance but problem is that I'll probably have trouble validating the XML with the new attributes later when trying to load it back again. (because the attributes I add to the XML are not defined in his schema)

Do you have a better solution for this problem? Which of the solutions you would vote on? (Please explain.)

Thanks!

+1  A: 

Hi Ran,

It's not clear from your question if the additional meta-data is generated once, or need to be stored and used in subseqeunt loads.

You may consider using XSLT to generte the new XML with the meta-data. If the new data is failry straight forward and deduced from the original XML, you can use XSLT to easily generate meta-data per node. If it's predictable and consistent, you can repeat the process whenever you load the data and get the same new XML. If it's not predictable, for example, if you need to create the XSLT on the fly, you may still be able to store the XSL once its generated, and then use that over time to re-generate the same new XML from original XML.

Per your suggested solutions:

  1. Referncing by XPATH: good if the original XML doesn't change and you can built definitive XPATHs.
  2. Referencing by node id: good, but you'll need to add ids to the original XML if you don't have already, and you will need to update the ids if the original changes (so you may need an id counter to assign ID, or otherwise use generated GUID as ids).
  3. If you want to add the meta-data to the original XML, you can either update the schema or create a new one for 'updated docs' (and change the schema reference in the XML document).

Regards, Inbar

Inbar Shani
Thanks for the detailed response.Regarding your question, I'll need to store it and use it in subsequent loads in my control's de-serialization.
Ran