1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#! /usr/local/bin/ruby
## ID attribute for XPointer test implementation
## 1998 by yoshidam
require 'xml/dom/builder'
## create test XML tree
doc = XML::DOM::Builder.new.parse("
<test>
<section name=\"section1\">
<p id='para1'>test</p>
<p id='para2'>test</p>
</section>
<section name=\"section2\">
</section>
</test>
")
## setup ID attribute
doc._setIDAttr('id') ## for all element
doc._setIDAttr('name', 'section') ## for section element
## find ID attribute
p doc.getNodesByXPointer("id(section1)")[0].makeXPointer(false)
p doc.getNodesByXPointer("id(section1)")[0].makeXPointer(true)
p doc.getNodesByXPointer("id(para1)")[0].makeXPointer(false)
p doc.getNodesByXPointer("id(para1)")[0].makeXPointer(true)
|