We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here's a tiny patch implementing the functionality talked about here[0].
[0] http://rubyforge.org/pipermail/nokogiri-talk/2009-March/000224.html
diff --git a/lib/nokogiri/xml/builder.rb b/lib/nokogiri/xml/builder.rb index 89cd63a..5cdcafd 100644 --- a/lib/nokogiri/xml/builder.rb +++ b/lib/nokogiri/xml/builder.rb @@ -277,6 +277,12 @@ module Nokogiri @doc.to_xml end + ### + # Append the given raw XML +string+ to the document + def << string + @doc.fragment(string).children.each { |x| insert(x) } + end + def method_missing method, *args, &block # :nodoc: if @context && @context.respond_to?(method) @context.send(method, *args, &block) diff --git a/test/xml/test_builder.rb b/test/xml/test_builder.rb index d4a6e26..12b1f86 100644 --- a/test/xml/test_builder.rb +++ b/test/xml/test_builder.rb @@ -117,6 +117,26 @@ module Nokogiri assert_equal 'hello', builder.doc.at('baz').content end + def test_raw_append + builder = Nokogiri::XML::Builder.new do |xml| + xml.root do + xml << 'hello' + end + end + + assert_equal 'hello', builder.doc.at('//root/foo').content + end + + def test_raw_append_with_instance_eval + builder = Nokogiri::XML::Builder.new do + root do + self << 'hello' + end + end + + assert_equal 'hello', builder.doc.at('//root/foo').content + end + def test_cdata builder = Nokogiri::XML::Builder.new do root { -- 1.6.4.3
The text was updated successfully, but these errors were encountered:
I've applied the patch, but next time please make sure the tests pass. After applying the patch, I got these errors:
1) Error: test_raw_append(Nokogiri::XML::TestBuilder): NoMethodError: undefined method `content' for nil:NilClass test/xml/test_builder.rb:127:in `test_raw_append' 2) Error: test_raw_append_with_instance_eval(Nokogiri::XML::TestBuilder): NoMethodError: undefined method `content' for nil:NilClass test/xml/test_builder.rb:137:in `test_raw_append_with_instance_eval'
Sorry, something went wrong.
XML Builder can append raw strings. closed by 98b10d2
Yeah, I pasted the wrong patch. Sorry about that.
No problem! :-)
No branches or pull requests
Here's a tiny patch implementing the functionality talked about here[0].
[0] http://rubyforge.org/pipermail/nokogiri-talk/2009-March/000224.html
The text was updated successfully, but these errors were encountered: