[xsde-users] xsde xpath generation
boris at codesynthesis.com
Wed Feb 1 14:41:08 EST 2012
Sia Jeffry Saputra <ssaptura at sta.samsung.com> writes:
> Probably to clear things up, the scenario I was trying to solve
> is like below:
> For example: both server and client have book schema.
> 1. Client has book data and corresponding data object called book object.
> <book category="CHILDREN">
> <title lang="en">Harry Potter</title>
> <author>J K. Rowling</author>
> 2. Client modified the book's object above. Let say year 2005 to 2010
> 3. The server has interface to access a particular node, so instead
> of replacing the whole book, we can use xpath to change particular node.
> Like eg: request ("book/year", 2010);
> 4. So since the client side is working on the data object book.
> It can change it with book.year = 2010 and then store it locally.
> 5. But to modify the server, I am just wondering is there any method
> to have something like giving the node as parameter and return the
> generated xpath query?
> Something like: xpathquery = foo (book.year); which will return the
> "book/year" query so I can construct the request to server accordingly.
I understand better now. Unfortunately I can't think of a way to get
this with XSD/e. Such a feature would require each node in the object
model to store some kind of a map of child nodes to their names. Each
node will also need to store a reference to its parent so that the
whole model can be traversed from a child to its ultimate parent
(this description should actually remind us of something that has
these properties -- DOM). So as you can see, this feature would
require quite an elaborate data structure. And this is without even
thinking about fundamental types (what if year is int, how can one
possibly store a reference to parent there?).
One way to make this problem more tractable would be to require a
schema to define a unique type for each element/attribute. Then you
could create a map between types and their XPath expressions. In
fact, if you make each type name encode its XPath, then you could
derive the XPath expression directly from typeid(book.year).name().
For example, if year's type is book_year_t, then you could easily
convert it to the book/year XPath expression.
You could also probably achieve something like this with XSD using
the DOM association feature (maintains an association between DOM
and object model nodes). Though the DOM association is not
automatically updated when the object model is modified.
More information about the xsde-users