To make things better I have created some regular expressions that will allow me to write XPaths the way I want to write them and still have them work with real XPath engines out there. It makes the XPath ignorant towards namespaces that are not defined in my XPath query. Namespaces that are defined in my XPath query will be handled like before.
if(!xpath.StartsWith("/")){
xpath= "./" + xpath;
}
xpath = Regex.Replace(xpath,@"/(?[\w]+)\[","/*[local-name()=='${node}' and ");
xpath = Regex.Replace(xpath,@"/(?[\w]+)","/*[local-name()=='${node}']");
PS. I'll get back to the post and tidy the code up later
You might want to add a few tests for the code to make sense.
ReplyDeleteHi Ronnie. what the code does is to convert a XPath like this:
ReplyDeleteArrayOfSObject/sObject[sadf='234']/Initial_distribution_channel
into something like this:
./*[local-name()='ArrayOfSObject' ]/*[local-name()='sObject' and sadf='234']/*[local-name()='Initial_distribution_channel__c']
The result should be that the second ignores the namespaces
That is; pretty neat!
ReplyDelete