Most modern databases have XML functions that can be used to extract data in an XML format. I want to avoid the task of manually calling XML functions to extract the data.
This problem involves devising a generic solution to create XML documents based on mapping database tables (and
JOIN conditions) to XPath expressions.
An XPath map codifies associations between an XML document and relational data as follows:
root > people -- "root" is a special keyword person > person -- > is a node to table relation person.first_name -> name/first -- -> is a node/attribute to column relation person.last_name -> name/last person.age -> [@age] account.person_id => person.person_id -- => is a join account > person/account account.number -> [@id]
PERSON table might resemble:
person_id | first_name | last_name | age 123 | Peter | Parker | 18 456 | James | Jameson | 42
ACCOUNT table might resemble:
account_id | person_id | number 1 | 123 | 123456789
Calling a function using the XPath map would produce the following XML document:
<people> <person age="18"> <name> <first>Peter</first> <last>Parker</last> </name> <account id="123456789" /> </person> <person age="42"> <name> <first>James</first> <last>Jameson</last> </name> </person> </people>
In this case, James Jameson does not have an account and so the corresponding XML element (
account) is not included in the final document.
This is a difficult problem and a complete solution is not necessary. A solution that handles 80% of simple tables mapped to simple XML elements and attributes would suffice.
What algorithm would return an XML document based on such a generic XPath map? The algorithm must transform the structure defined by the XPath map into an XML document with the content from the relations defined in the XPath map.
Links that are somewhat related to this idea.
Articles and White Papers