英文:
Does xpath explicitly allow undefined variables?
问题
I was trying to pull some data out of an XML file using xmlstarlet, but xmlstarlet sel -t -v '//div[contains(@class,"addresses")]/a'
was getting me a lot more than I expected. I finally worked out - with the help of replacing -v
with -c
to debug the xpath - that it was because the single quotes around 'addresses' were vanishing because the whole argument is single-quoted: replacing that with "addresses" worked as expected. What I'm really confused about is quite what contains(@class,addresses)
does - because xmlstarlet didn't flag it as an error or warn about it, even though I presume it's treated as an undefined variable. I checked the source in https://github.com/fishjam/xmlstarlet/blob/master/src/xml_select.c but I can't spot a 'warnings' flag - should there be something like that, or are xpaths defined to allow this?
英文:
I was trying to pull some data out of an XML file using xmlstarlet, but
xmlstarlet sel -t -v '//div[contains(@class,'addresses')]/a'
was getting me a lot more than I expected.
I finally worked out - with the help of replacing -v
with -c
to debug the xpath - that it was because the single quotes around 'addresses'
were vanishing because the whole argument is single-quoted: replacing that with "addresses"
worked as expected.
What I'm really confused about is quite what contains(@class,addresses)
does - because xmlstarlet didn't flag it as an error or warn about it, even though I presume it's treated as an undefined variable.
I checked the source in https://github.com/fishjam/xmlstarlet/blob/master/src/xml_select.c but I can't spot a 'warnings' flag - should there be something like that, or are xpaths defined to allow this?
答案1
得分: 2
在 contains(@class,addresses)
中,addresses
选择上下文节点(即在 //div[contains(@class,addresses)]
中,div
元素中的断言 [contains(@class,addresses)]
所属的可能的子元素名为 addresses
的元素;一个变量(引用)将被写作 $addresses
。
英文:
In contains(@class,addresses)
, addresses
selects (possible) child elements named addresses
of the context node (i.e. in //div[contains(@class,addresses)]
the div
element the predicate [contains(@class,addresses)]
belongs to); a variable (reference) would be written as $addresses
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论