Answer the question
In order to leave comments, you need to log in
A snag in creating XML in Ruby (via nokogiri)
Using ruby, I create XML for WordPress
There is such a structure of tags
, etc.
I found an example:
But it gives extra lines as a result (root):
Please tell me how to get only the necessary lines,
i.e.
<content:encoded>text</content:encoded>
<wp:id>text</wp:id>
<wp:menu_order>text</wp:menu_order>
builder = Nokogiri::XML::Builder.new do |xml|
xml.root('xmlns:content' => 'bar') {
xml['xmlns:content'].encoded{xml.text "text"}
}
end
puts builder.to_xml
<?xml version="1.0"?>
<root xmlns:content="bar">
<content:encoded>text</content:encoded>
<content:encoded>text</content:encoded>
Answer the question
In order to leave comments, you need to log in
In general, well-formed XML should contain one and only one root element . nokogiri creates it for you by default, obviously.
So find in the documentation what the root element should be in your case and wrap it in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question