I have a very simple XML snippet that is stored in a file that needs to be updated.
Unfortunately it is a processing instruction that I need to have updated.Can I use XPath to get the content of the processing instruction, or at least part of it?
For example:
<Include>
<?define Version="2.0"?>
</Include>
I need to get the value of "Ver开发者_开发百科sion".
This XPath expression:
substring-before(
substring-after(
/Include/processing-instruction('define'),
'Version="'
),
'"'
)
Evaluate to the string: '2.0'
I don't think you can get '2.0'. You can get 'Version="2.0"' in a single value, then manually extract the '2.0' out of it. It is part of xml spec. If you wish to get 2.0, make sure that you use <define Version='2.0/>
(use element instead of processing instruction).
Quoting from here,
The "attributes" in processing instructions aren't actually attributes -- they just look like them. Noramally people refer to these kinds of "attributes" as "pseudo-attributes" to emphasise that fact. As far as the XPath data model is concerned, the only information you can get about a processing instruction is its target, its value and its location in the node tree.
So you can get to the node itself with
/Include/processing-instruction('define')
but all that gets you is a node with a Value
of Version="2.0"
(as a string), which you must then parse yourself.
精彩评论