I am trying to isolate a part of an XML document that uses namespaces using nokogiri:
require 'nokogiri'
xml= "<s:Some xmlns:s=\"http://nmsc.com/nmsc\"><s:One></s:One></s:Some>"
n= Nokogiri.XML(xml)
n.xpath("//s:One", :s=>"http://nmsc.com/nmsc")[0].to_xml
This ignores the namespace and simply outputs
"<s:One/>"
How can I generate XML with the correct namespace, i.e.:
<s:One xmlns:s="http://nmsc.com/nmsc" />
?
Interestingly, there is a namespace:
> n.xpath("//s:One", :s=>"http://nmsc.com/nmsc")[0]
=>
name = "One",
namespace =
prefix = "s",
href = "http://nmsc.com/nmsc"
})
})
but to_xmldoes not include it.
source
share