Saturday, March 10, 2012

XPathBridgeTransformer Continued

You could try http://www.w3schools.com/xpath/xpath_syntax.asp for some basic xpath syntax...

I believe you want ../@.precision or something like that, where .. means select from parent node, and @. means attribute...

Hope that helps,
-Hao

Right, I've tried using the @., but I'm not really sure where to put it. I mean, should it look like this?

<dictionary name="selectedNodes"> <item name="Latitude" value="yn:Latitude" /> <item name="Longitude" value="yn:Longitude" /> <item name="Precision" value="../@.precision" /></dictionary>
Does the yn namespace need to be referenced?
Thanks,
Pete


The best thing to do in general for these issues is just to tryit. You have the xml, so you can construct an XMLDocument fromthe xml, and then try out your XPath queries in a little consoleapp. That's the best way to debug your xpath queries...

Hope that helps,
-Hao
The problem is not so much the xpath queries as it is the structure of the transform element. Is that documented somewhere yet?
Unfortunately there's not much documentation currently, but basically,all this transformer is doing is calling SelectNodes on the documentelement using the selector attribute with the namespaces added to anamespace manager. And then it calls SelectSingleNode with eachitem in the data and adds the inner text to the results array.

If the XPathBridgeTransformer is not able to exactly perform thetransformation you need, you can always write your own bridgetransformer specifically for this xpath transform...

Hope that helps,
-Hao

If it's only calling SelectNodes and SelectSingleNode (+innerText), wouldn't it be safe to say that the XPathBridgeTransformer can't transform attributes?

Thanks,
Pete


That's not quite true since if you call SelectSingleNode(@.attribute) itwill give indeed give you a node representing the attribute where theinnerText represents the value of the attribute.

Sorry, this reveals what a novice I am with XPath. I was equating Node with XmlElement. My big problem came from trying to qualify the attribute with the namespace, but that ended up not being necessary. Here's what I ended up doing:

 <transform type="Microsoft.Web.Services.XPathBridgeTransformer"> <data> <attribute name="selector" value="yn:Result" /> <dictionary name="namespaceMapping"> <item name="yn" value="urn:yahoo:maps" /> </dictionary> <dictionary name="selectedNodes"> <item name="Latitude" value="yn:Latitude" /> <item name="Longitude" value="yn:Longitude" /> <item name="Precision" value="@.precision" /> </dictionary> </data> </transform>

No comments:

Post a Comment