Normalize, literally means normalization, plus space, roughly means the processing of space.
The official explanation is as follows:
By removing leading and trailing whitespace and replacing a series of whitespace characters with a single space, the whitespace is standardized. If this parameter is omitted, the string value of the context node is normalized and returned.
.
is the current node. If you use it where you need a string (for example, as a parameter normalize space()
), the engine automatically converts the node to the string value of the node, which, for the element, is all the text nodes connected within the element.
text ()
on the other hand, only the text node that is the direct child of the current node is selected.
For example, given XML:
<a&>Foo
<b&>Bar</b&> lish </a&>
Assuming & lt; a &>
is your current node, normalize space (.)
will return foo bar list
, but normalize space (text ())
will fail because text ()
returns a node set of two text nodes ( foo
and List
), which normalize space ()
does not accept.
To make a long story short, if you want to standardize all the text in an element, use .
. If you want to select a specific text node, use text()
, but always remember that although the name is different, text()
returns a node set, which is automatically converted to a string if it has only one element.
Similar Posts:
- Function of double slash in XPath / / double slash
- [Solved] DOM Add Element to HTML Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’
- [Solved] DOM adds elements to HTML Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of typ…
- How to Solve Issue: ScrollView can host only one direct child
- How to Solve stale element reference: element is not attached to the page document
- [How to Solve] no suitable node (host-mode port already in use on 1 node)
- Inkscape – rounding corners of shapes
- [Solved] the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
- [Solved] Exception in thread “main” java.util.ConcurrentModificationException
- InvalidSelectorError: Compound class names not permitted [How to Solve]