Sha256: fd9749a195b720dadfad8cb80845e42e08c87ab321be839b4752275c50b83000
Contents?: true
Size: 853 Bytes
Versions: 3
Compression:
Stored size: 853 Bytes
Contents
require 'xml/xxpath' d=REXML::Document.new <<EOS <foo> <bar/> <bar/> </foo> EOS rootelt=d.root XML::XXPath.new("*").all(rootelt) => [<bar/>, <bar/>] ### ok XML::XXPath.new("bar/*").first(rootelt, :allow_nil=>true) => nil ### ok, nothing there ### the same call with :ensure_created=>true newelt = XML::XXPath.new("bar/*").first(rootelt, :ensure_created=>true) => </> d.write($stdout,2) <foo> <bar> </> </bar> <bar/> </foo> ### a new "unspecified" element was created newelt.unspecified? => true ### we must modify it to "specify" it newelt.name="new-one" newelt.text="hello!" newelt.unspecified? => false d.write($stdout,2) <foo> <bar> <new-one>hello!</new-one> </bar> <bar/> </foo> ### you could also set unspecified to false explicitly, as in: newelt.unspecified=true
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
pdf-labels-1.0.0 | vendor/xml-mapping/examples/xpath_pathological.intout |
xml-mapping-0.8 | examples/xpath_pathological.intout |
xml-mapping-0.8.1 | examples/xpath_pathological.intout |