PDA

View Full Version : Passing datapath to object


JApostoles
11-03-2004, 06:59 AM
Given an XML file like this:


<items>
<item>
<text>Some Text</text>
<children>
<child id="1">more text</child>
<child id="2">more text</child>
</children>
</item>
</items>


If I pass a string contaning a datapath to an object, and then use that string as the datapath for the view containing the object, it seems I cannot access the children two-deep.

Example:
If I pass "myData:/items/item" as the datapath string, and then use that in the view, "$path{'text/text()'}" will return "Some Text", which is correct, but if I do $path{'children/child[@id=\\'1\\']/text()'} it doesn't return anything.

Any ideas?

JApostoles
11-03-2004, 07:42 AM
I figured it out on my own. Oddly enough, you do not need to escape single quotes within a path. Thus:


$path{'myData:/rootNode/childNode[@id=\\'1\\']'}


is incorrect.. the correct syntax is:


$path{'myData:/rootNode/childNode[@id='1']'}

rbrown3
11-03-2004, 01:43 PM
Um... your "incorrect" syntax and your "correct" syntax look exactly the same.

How exactly did you use this $path statement to access your specific text? What was the exact syntax???

JApostoles
11-04-2004, 06:46 AM
Looks like the forum stripped out my escaped quotes
;-)

The incorrect code should look like this:


$path{'myData:/rootNode/childNode[@id=\\'1\\']'}


I read somewhere you had to escape single quote characters in this case, and of course normally you should since most compilers would interpret an unescaped singe quote as the end of a string since there's already a single quote in the beginning. This wont work with Laszlo though, you need to use the single quotes unescaped as so:


$path{'myData:/rootNode/childNode[@id='1']'}