Sha256: 7edde6330049320833f435992be2fdc71ccea1f8a0cb77a8bd47bc42a75b5fd4

Contents?: true

Size: 916 Bytes

Versions: 3

Compression:

Stored size: 916 Bytes

Contents

#!/usr/bin/ruby
require "#{File.dirname($0)}/../smart"

# No closure, so changes are temporary
doc = XML::Smart.open(File.dirname($0) + "/EXAMPLE.xml")

# add an element hallo to root
nsnode = doc.root.add("hallo")

# add a namespace to the element
ns = nsnode.namespaces.add("test","http://heise")

# has the element a namespace? - No
p nsnode.namespace?

# set one
nsnode.namespace = ns

# has the element a namespace? - Yes
p nsnode.namespace?

# inspect the namespace + print (to_s)
p ns

# add a node, a namespace, then add the namespace to the element (via a string)
nsnode = doc.root.add("hallo")
nsnode.namespaces["sulu"] = "http://slashdot"
nsnode.namespace = "sulu" # nsnode.namespace = "http://slashdot" would have worked also
nsnode.namespaces["sulu"] = "http://slashdot/test"

# find namspaces
p nsnode.namespaces.find("soap")
p nsnode.namespaces.find("http://slashdot/test")

# print document
puts doc

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-xml-smart-0.1.12.1-i486-linux examples/namespace_detailed.rb
ruby-xml-smart-0.1.12-i486-linux examples/namespace_detailed.rb
ruby-xml-smart-0.1.11-i486-linux examples/namespace_detailed.rb