茴字的第一种写法是XML,茴字的第二种写法是xml2。
想到哪写到哪,很乱:
xml_length()相当于xmlSize();
xml_text() xml_integer() xml_double()相当于xmlValue();
XML格式冗余度高,这要求XML包可以直接读取zip压缩过的xml文件,这点xml2的read_xml()也可以做到。大概是因为底层的库都是libxml2吧。
同一个xml文件,xml2解析出来的class和XML解析出来的不一样。说一说xml2的两个class xml_node和xml_nodeset
xml2对于xml_nodeset class,用[[]]来选出xml_node、或用[]选出xml_nodeset;
对于xml_node class,不能用[[或[;只能用xml_children()对xml_node或xml_nodeset取xml_nodeset。
> class(xml_children(doc)[[1]])
[1] "xml_node"
> class(xml_children(doc)[1])
[1] "xml_nodeset"
再来复习一下[[和[的区别:
The most important distinction between [, [[ and $ is that the [ can select more than one element whereas the other two select a single element.
[[只限单选,[可以多选;
The usual form of indexing is [. [[ can be used to select a single element dropping names, whereas [ keeps them, e.g., in c(abc = 123)[1].
[[会把name丢掉,[会保留name,这个原则对xml_node也一样,generic。
——不过对xml查询来说,反正有xpath,不用[[和[也可以。