"value substitution/population" in template XML using XPath




Hello,
I'm stuck on this problem for quite some time and hope somebody would
be able to guide me.

Basically, I need to populate a large number of "template" XML files
which have all elements/attributes etc. defined but the values in these
elements/attributes might be blank or place holders, as two examples
below:

Example - File type 1
<?xml version="1.0" encoding="UTF-8"?>
<fileType1>
<element1>
<element2 attr2="xxx">
<element3>
<element4 attr4="yyy">
</element4>
</element3>
</element2>
</element1>
</fileType1>


or

Example - File type 2
<?xml version="1.0" encoding="UTF-8"?>
<fileType2>
<element1>
<element2 attr2="xxx">
<element13>
<element14>
<element15>ZZZ</element15>
</element14>
</element13>
</element2>
<element3>
</element3>
</element1>
</fileType2>


and the new values to be populated (or atleast their XPath) are
indicated in a seperate XML data file as, and easily obtained as
xpath/value pair using Java or XSLT etc.:

<?xml version="1.0" encoding="UTF-8"?>
<newValues>
<file type="fileType2">
<element>
<x-path>/fileType2/element1/element3</x-path>
<value>newValue3</value>
</element>
<element>
<x-path>/fileType2/element1/element2/@attr2</x-path>
<value>ABC</value>
</element>
<element>
<x-path>/fileType2/element1/element2/element13/element14/element15</x-path>
<value>newValue15</value>
</element>
</file>
<file type="fileType1">
<element>
<x-path>/fileType1/element1/element2/@attr2</x-path>
<value>123</value>
</element>
<element>
<x-path>/fileType1/element1/element2/element3/element4/@attr4</x-path>
<value>999</value>
</element>
</file>
</newValues>



So what is the best approach to read the 'template' example file(s) and
output it with new values for xpath indicated in the data file?

I have used DOM/JDOM to perform this task at a limited scale, but the
complicating factors are:

- the number of unique "template" files is rather large (all
generated from relevent XSD)
- the structure of each template is quite deep/complex
- the number of xpath/value would be arbitrary (say min of 5 "fields"
to be changed, max all of them!)

Essentially this task is a 'value substitution' or 'data population'
problem for an XML file, where the xpath/value pair are indicated in
another XML file. IMHO (re)constructing the output XML from scratch
appears would be overkill, and not feasbile to do it programatically in
Java code etc. Hence my search for a more efficient way to do it, say
with XSLT or some other technique, which 'processes' the original XML
input file WITHOUT altering the structure but substituting the desired
values as required.

Would appreciate any and all help in this regards!

Regards,

Bilal B.


--
Bilal
------------------------------------------------------------------------
Bilal's Profile: http://techiegroups.com/member.php?userid=336
View this thread: http://www.techiegroups.com/showthread.php?t=116624

.



Relevant Pages

  • What Not to Do (a cautionary tale)
    ... script that reads in an XML file and an ERB template, ... to the template, and writes out the result to a file. ... and all hell broke loose as a result. ... Don't upgrade your Ruby environment unless you need to ...
    (comp.lang.ruby)
  • plugin architecture - repost
    ... I am building an application to help researcher record the outcomes of their ... These outcomes are document across a number of paper forms. ... I've created a number of these 'template' files. ... to use a specific template, I open the XML file, deserialize it, add data to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Word 200 Macro using replace
    ... this field is populated from different fields in an XML file. ... The carraige ... returns aren't part of the template, they come from the XML file". ... > create a macro that will run automatically everytime a new .doc file is ...
    (microsoft.public.word.docmanagement)
  • Re: Searching through a structure
    ... > I want to read in string parameters from an XML file to populate this ... The member names disappear at compile time. ...
    (microsoft.public.vc.mfc)
  • Add or Modify Templates
    ... Office2007 RibbonXML for use in Office Template AddIns. ... General and XML File and a new blank XML file is created in the code window. ... named Ribbon XML Basic that creates a new XML as follows: ... I have found the XMLFile.zip folders in the Item Templates and Item ...
    (microsoft.public.vstudio.development)