File: idattrtest.rb

package info (click to toggle)
libxml-parser-ruby 0.6.1-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 676 kB
  • ctags: 800
  • sloc: ruby: 5,723; ansic: 1,734; xml: 574; makefile: 152
file content (28 lines) | stat: -rwxr-xr-x 744 bytes parent folder | download | duplicates (2)
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 'xmltreebuilder'

## create test XML tree
doc = XML::SimpleTree::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)