Nick,
>I have finally got round to applying this suggestion to our live XML file. Problem is the Child.ParentID field is .null., any ideas why that might be. I guess it is the
'parent::<childalias>/<parentIdField>'
which is not getting evaluated as expected but can't find any way of looking at what is going on. Is there any way of debuging the
parent::<childalias>/<parentIdField>
line to see if it is working correctly?
>
>Our XML has six tables within it.
I added pre tags around your xml ref above to make your question clearer. You show
parent::childalias/parentIdField, but that should be
parent::parentalias/parentIdField.
XPath expressions in XMLAdapter are evaluated relative to the node's next higher hierarchical level, which in the case of an XMLField object will be in the context of the XMLTable you're going to add the XMLField to. So, in Aleksey's example of adding a field to the BAR table and referencing a field in the foo table, the
parent::foo/f1 expression (IF I understand it correctly) means this:
Start at the table node this field will be added to (BAR) and evaluate the XPath expression. In Aleksey's example, parent:: of the BAR table will be the "root node" of the XML document (VFPData) -- not the FOO table as you might have expected, because XMLAdapter sees all table objects as immediate children of the root node, whether nested or not (I'm really guessing on this, but it's the only thing that makes sense -- I'm sure Aleksey will correct me if I'm wrong -- help, Aleksey!). After evaluating "parent::" to mean the root node, XMLAdapter then works down the hierarchy from there to the foo table and its f1 field and will put its value into the new XMLField object being added to the BAR table.If you could post your code and also at least a skeleton of the XML structure showing how the tables are set up and nested, etc, I could help you better. But, as a simple test, just use the alias of the table containing the field you want to reference instead of the "childalias" that you mentioned above. Also, be sure to note that XPath expressions are case-sensitive and must exactly match the tags in the XML document.