Do I need to “find” return nodes in order?

Do XML::LibXML::Node::find and related methods ensure that the list of nodes is always ordered, as in an XML document?

This is important to me because my document corresponds to a large array in which I want to be able to delete a number of elements under certain circumstances, and I have to make sure that something like this works sequentially:

 my @nodes = $dom->find('//MyElement[@attr=something]/descendant::Token/@id') ->get_nodelist; for my $token ( reverse map { $_->value } @nodes ) { splice @my_big_array, $token, 1; } 

The difficulty is that it is not described in XML::LibXML , and I don’t know if it depends on the libxml2 implementation, the documentation I really don’t understand, or on the DOM standard or some other W3C standard that are clearly not were written to read my mere mortals.

+6
source share
2 answers

I essentially answered this question on the corresponding question . XML::LibXML calls xmlXPathCompile from libxml2, which ensures that the resulting node -set is sorted in document order.

+1
source

As far as I know, the current XML standard really cares about the order of the nodes, and the current XML :: LibXML implementation will give you the same order every time.

More: In XML, is order important? Does XML mean ordering?

Good reading about this: http://www.ibm.com/developerworks/xml/library/x-eleord/index.html

1: it needs to be ordered so that every start of the same parser returns the same result. 99% of parsers use the order in the xml file, the remaining orders in order in the scheme

The XML information set (InfoSet - see the Resources section), the main data The XML model defined by the W3C characterizes the child elements as: an ordered list of child information elements, in document order.

2: ordering can be forced or deleted

Ampersand characters (&) between the subpatterns of the twin elements indicate that any order is acceptable.

 element memo { element title { text } & element date { text } & element from { text } & element to { text } & element body { text } } 
+2
source

Source: https://habr.com/ru/post/969958/


All Articles