是否可以像这样获取以下元素的属性并在前面的元素中使用它们?:
<title>Section X</title>
<paragraph number="1">Stuff</paragraph>
<title>Section Y</title>
<paragraph number="2">Stuff</paragraph>
进入:
<title id="ID1">1. Section X</title>
<paragraph number="1">Stuff</paragraph>
<title id="ID2">2. Section Y</title>
<paragraph number="2">Stuff</paragraph>
我有类似的东西,但得到节点集或字符串错误:
frag = Nokogiri::XML(File.open("test.xml"))
frag.css('title').each { |text|
text.set_attribute('id', "ID" + frag.css("title > paragraph['number']"))}