Populate XML template-file from XPath Expressions?

reza63

New Member
What would be the best way to populate (or generate) an XML template-file from a mapping of XPath expressions?The requirements are that we will need to start with a template (since this might contain information not otherwise captured in the XPath expressions).For example, a starting template might be:\[code\]<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'> <ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/'> <article xmlns:ns1='http://predic8.com/material/1/'> <name>?XXX?</name> <description>?XXX?</description> <price xmlns:ns1='http://predic8.com/common/1/'> <amount>?999.99?</amount> <currency xmlns:ns1='http://predic8.com/common/1/'>???</currency> </price> <id xmlns:ns1='http://predic8.com/material/1/'>???</id> </article> </ns1:create> </s11:Body></s11:Envelope>\[/code\]Then we are supplied, something like:\[code\]expression: /create/article[1]/id => 1expression: /create/article[1]/description => barexpression: /create/article[1]/name[1] => fooexpression: /create/article[1]/price[1]/amount => 00.00expression: /create/article[1]/price[1]/currency => USDexpression: /create/article[2]/id => 2expression: /create/article[2]/description => some nameexpression: /create/article[2]/name[1] => some descriptionexpression: /create/article[2]/price[1]/amount => 00.01expression: /create/article[2]/price[1]/currency => USD\[/code\]We should then generate:\[code\]<ns1:create xmlns:ns1='http://predic8.com/wsdl/material/ArticleService/1/'> <article xmlns:ns1='http://predic8.com/material/1/'> <name xmlns:ns1='http://predic8.com/material/1/'>foo</name> <description>bar</description> <price xmlns:ns1='http://predic8.com/common/1/'> <amount>00.00</amount> <currency xmlns:ns1='http://predic8.com/common/1/'>USD</currency> </price> <id xmlns:ns1='http://predic8.com/material/1/'>1</id> </article> <article xmlns:ns1='http://predic8.com/material/2/'> <name>some name</name> <description>some description</description> <price xmlns:ns1='http://predic8.com/common/2/'> <amount>00.01</amount> <currency xmlns:ns1='http://predic8.com/common/2/'>USD</currency> </price> <id xmlns:ns1='http://predic8.com/material/2/'>2</id> </article></ns1:create>\[/code\]I am implemented in Java, although I would prefer an XSLT-based solution if one is possible.PS: This question is the reverse of another question I recently asked.
 
Back
Top