Open BdR76 opened 1 year ago
I agree xpath evaluation on namespaced xml is not straightforward and I'll try to make this easier... just don't know when 😩
Currently, namespaces declared in xpath evaluation dialog must be named and expression must use these names, for instance:
XPath: /x:Bundle/x:entry/x:resource/x:ValueSet/x:name/@value Namespace: xmlns:x='http://hl7.org/fhir'
Thanks for showing how the namespace and xpath should be formatted in this case, that does work. 👍 I think when the namespace is incorrectly formated, then the plug-in could implicitly interpret the namespace by adding xmlns:x=
and xpath x:
. Either that, or explicitly correct the namespace formatting by first prompting the user.
So for example in the onExit (of onValidate) of the namespace textbox, check if namespace is correctly formatted, and if not prompt user to auto-reformat it. So something like:
1) user enters XPath /Bundle/entry/resource/ValueSet/name/@value
in first textbox
2) user changes namespace in second textbox to http://hl7.org/fhir
3) The onExit checks if the namespace textbox starts with xmlns
4) if it doesn't, then prompt user Not formatted properly, do you want to auto-format namespace? yes/no
5) If user answers yes
then correctly reformat the namespace value and add the x:
to all XPath tags
imho that would go a long way in making it more userfriendly to search with namespaces. Or maybe the Plugins > XML Tools > Current XML path
menuitem could also copy the namespace to the clipboard somehow?
Description of the problem
I'm trying to extract specific information from a large XML file using Notepad++ and the XML Tools plug-in. I've copied the XPath through the XML Tools menu
Plugins > XML Tools > Current XML path
and I've pasted that in the "XPath expression" dialog. However, I just get "no result" and no further hints from the XML Tools dialog, and I've got no clue what to do next. I suspect it has to do with xml namespace and I've tried entering different namespaces but no matter what I enter I get the same "no results", so at this point I'm just blind guessing.Example
See example XML file in the attachement (the real file is larger, about 2.5MB)
I move the cursor to the first name value, so
"Anomaly location"
, and then select the menu itemPlugins > XML Tools > Current XML path
. It copies the XPath which is "/Bundle/entry/resource/ValueSet/name/@value" and as far as I can see this is the correct XPath.Then I go to the menu item
Plugins > XML Tools > Evaluate XPath expression
. In the textbox for XPath expression I paste the xpath/Bundle/entry/resource/ValueSet/name/@value
, and leave the textbox "Namespace definition" empty. When I press the button "Evaluate" I just getno result
. Btw I also tried enteringhttp://hl7.org/fhir
in the textbox "Namespace definition" but that gives the same result.For this small example file I would expect the result to be something like this:
Additional notes
I suspect that it has to do with xml namespaces, because previously I've had trouble with that as well, using different tools on a different case. But, if that is indeed the case, is it possible for XML Tools to evaluate the XPath and ignore the exact namespace?
Also, if there is some obvious mistake in the XPath, like if it requires
[]
or*
at the end or something like that, maybe the dialog could give a hint or suggestion to what the XPath should be?Notepad++ debug info, should it be needed