tenderlove/nokogiri — Issue #624: Raw XML
Author: semperos
Created: 2012-02-24 22:31:06+00:00
State: open

I've seen `<<` being used to append raw XML to a Builder, like this:

```rb
builder = Nokogiri::XML::Builder.new do |xml|
doc.test do
doc << ''
end
end
```

I also found this snippet on StackOverflow that reaches down and calles `insert` directly instead of using `<<`:

```rb
...
doc.__send__ :insert, Nokogiri::XML::DocumentFragment.parse(raw_xml_str)
...
```

Am I wrong in understanding this is how it should work?

```rb
doc << raw_xml_str
```

Accessing the `insert` method works, but using `<<` results in a `NoSuchMethodError` as follows:

```
XmlNode.java:720:in `isErrorIncreated': java.lang.NoSuchMethodError: org.jruby.RubyArray.compare(Lorg/jruby/runtime/ThreadContext;Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;Ljava/util/Set;)Lorg/jruby/RubyBoolean;
from XmlNode.java:686:in `in_context'
from XmlNode$i$2$0$in_context.gen:65535:in `call'
from CachingCallSite.java:332:in `cacheAndCall'
from CachingCallSite.java:203:in `call'
from FCallTwoArgNode.java:38:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:190:in `call'
from DefaultMethod.java:199:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from IfNode.java:117:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:120:in `call'
from InterpretedMethod.java:134:in `call'
from DefaultMethod.java:174:in `call'
from RubyClass.java:680:in `finvoke'
from RuntimeHelpers.java:557:in `invoke'
from XmlDocumentFragment.java:107:in `rbNew'
from XmlDocumentFragment$s$0$2$rbNew.gen:65535:in `call'
from JavaMethod.java:638:in `call'
from DynamicMethod.java:223:in `call'
from CachingCallSite.java:352:in `cacheAndCall'
from CachingCallSite.java:237:in `call'
from CallThreeArgNode.java:61:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:190:in `call'
from DefaultMethod.java:199:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from CallOneArgNode.java:57:in `interpret'
from CallNoArgNode.java:63:in `interpret'
from CallNoArgBlockNode.java:60:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:190:in `call'
from DefaultMethod.java:199:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from ShiftLeftCallSite.java:24:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
from InterpretedBlock.java:374:in `evalBlockBody'
from InterpretedBlock.java:328:in `yield'
from BlockBody.java:73:in `call'
from Block.java:89:in `call'
from RubyProc.java:270:in `call'
from RubyProc.java:220:in `call'
from RubyProc$i$0$0$call.gen:65535:in `call'
from DynamicMethod.java:211:in `call'
from DynamicMethod.java:207:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from IfNode.java:119:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from IfNode.java:117:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:212:in `call'
from DefaultMethod.java:207:in `call'
from CachingCallSite.java:322:in `cacheAndCall'
from CachingCallSite.java:178:in `callBlock'
from CachingCallSite.java:182:in `call'
from FCallOneArgBlockPassNode.java:32:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from IfNode.java:119:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:120:in `call'
from DefaultMethod.java:165:in `call'
from RuntimeHelpers.java:497:in `call'
from DynamicMethod.java:203:in `call'
from CachingCallSite.java:383:in `callMethodMissing'
from CachingCallSite.java:299:in `cacheAndCall'
from CachingCallSite.java:144:in `callBlock'
from CachingCallSite.java:153:in `callIter'
from CallNoArgBlockNode.java:64:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
from InterpretedBlock.java:374:in `evalBlockBody'
from InterpretedBlock.java:347:in `yield'
from InterpretedBlock.java:304:in `yield'
from Block.java:130:in `yield'
from YieldNode.java:119:in `interpret'
from NewlineNode.java:104:in `interpret'
from IfNode.java:119:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:169:in `call'
from DefaultMethod.java:191:in `call'
from CachingCallSite.java:302:in `cacheAndCall'
from CachingCallSite.java:144:in `callBlock'
from CachingCallSite.java:148:in `call'
from RubyClass.java:806:in `newInstance'
from RubyClass$i$newInstance.gen:65535:in `call'
from CachingCallSite.java:302:in `cacheAndCall'
from CachingCallSite.java:144:in `callBlock'
from CachingCallSite.java:153:in `callIter'
from CallNoArgBlockNode.java:64:in `interpret'
from DAsgnNode.java:110:in `interpret'
from NewlineNode.java:104:in `interpret'
from RootNode.java:129:in `interpret'
from ASTInterpreter.java:96:in `INTERPRET_EVAL'
from ASTInterpreter.java:161:in `evalWithBinding'
from RubyKernel.java:1124:in `evalCommon'
from RubyKernel.java:1077:in `eval'
from RubyBinding.java:134:in `eval'
from RubyBinding$i$0$2$eval.gen:65535:in `call'
from JavaMethod.java:638:in `call'
from DynamicMethod.java:223:in `call'
from CachingCallSite.java:352:in `cacheAndCall'
from CachingCallSite.java:237:in `call'
from CallThreeArgNode.java:61:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from RescueNode.java:216:in `executeBody'
from RescueNode.java:120:in `interpretWithJavaExceptions'
from RescueNode.java:110:in `interpret'
from EnsureNode.java:96:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:190:in `call'
from DefaultMethod.java:199:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from FCallOneArgNode.java:36:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:190:in `call'
from DefaultMethod.java:199:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from FCallOneArgNode.java:36:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
from InterpretedBlock.java:374:in `evalBlockBody'
from InterpretedBlock.java:295:in `yield'
from InterpretedBlock.java:229:in `yieldSpecific'
from Block.java:99:in `yieldSpecific'
from RubyKernel.java:1408:in `loop'
from RubyKernel$s$0$0$loop.gen:65535:in `call'
from CachingCallSite.java:302:in `cacheAndCall'
from CachingCallSite.java:144:in `callBlock'
from CachingCallSite.java:153:in `callIter'
from FCallNoArgBlockNode.java:32:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
from InterpretedBlock.java:374:in `evalBlockBody'
from InterpretedBlock.java:347:in `yield'
from InterpretedBlock.java:304:in `yield'
from Block.java:130:in `yield'
from RubyContinuation.java:106:in `enter'
from RubyKernel.java:1181:in `rbCatch'
from RubyKernel$s$1$0$rbCatch.gen:65535:in `call'
from CachingCallSite.java:322:in `cacheAndCall'
from CachingCallSite.java:178:in `callBlock'
from CachingCallSite.java:187:in `callIter'
from FCallOneArgBlockNode.java:34:in `interpret'
from LocalAsgnNode.java:123:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from EnsureNode.java:96:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:190:in `call'
from DefaultMethod.java:199:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:233:in `call'
from DefaultMethod.java:215:in `call'
from CachingCallSite.java:332:in `cacheAndCall'
from CachingCallSite.java:203:in `call'
from CallTwoArgNode.java:59:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
from InterpretedBlock.java:374:in `evalBlockBody'
from InterpretedBlock.java:328:in `yield'
from BlockBody.java:73:in `call'
from Block.java:89:in `call'
from RubyProc.java:270:in `call'
from RubyProc.java:220:in `call'
from RubyProc$i$0$0$call.gen:65535:in `call'
from DynamicMethod.java:211:in `call'
from DynamicMethod.java:207:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from CallOneArgNode.java:57:in `interpret'
from NewlineNode.java:104:in `interpret'
from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
from InterpretedBlock.java:374:in `evalBlockBody'
from InterpretedBlock.java:347:in `yield'
from InterpretedBlock.java:304:in `yield'
from Block.java:130:in `yield'
from RubyArray.java:1607:in `eachCommon'
from RubyArray.java:1614:in `each'
from RubyArray$i$0$0$each.gen:65535:in `call'
from CachingCallSite.java:302:in `cacheAndCall'
from CachingCallSite.java:144:in `callBlock'
from CachingCallSite.java:153:in `callIter'
from CallNoArgBlockNode.java:64:in `interpret'
from IfNode.java:117:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from ASTInterpreter.java:75:in `INTERPRET_METHOD'
from InterpretedMethod.java:147:in `call'
from DefaultMethod.java:183:in `call'
from CachingCallSite.java:292:in `cacheAndCall'
from CachingCallSite.java:135:in `call'
from CallNoArgNode.java:63:in `interpret'
from NewlineNode.java:104:in `interpret'
from BlockNode.java:71:in `interpret'
from RootNode.java:129:in `interpret'
from ASTInterpreter.java:120:in `INTERPRET_ROOT'
from Ruby.java:722:in `runInterpreter'
from Ruby.java:2479:in `loadFile'
from ExternalScript.java:66:in `load'
from LoadService.java:270:in `load'
from RubyKernel.java:1070:in `loadCommon'
from RubyKernel.java:1052:in `load'
from RubyKernel$s$0$1$load.gen:65535:in `call'
from DynamicMethod.java:211:in `call'
from DynamicMethod.java:207:in `call'
from CachingCallSite.java:312:in `cacheAndCall'
from CachingCallSite.java:169:in `call'
from /Users/semperos/.rvm/gems/jruby-1.6.6@global/bin/pry:19:in `__file__'
from /Users/semperos/.rvm/gems/jruby-1.6.6@global/bin/pry:-1:in `load'
from Ruby.java:695:in `runScript'
from Ruby.java:688:in `runScript'
from Ruby.java:595:in `runNormally'
from Ruby.java:444:in `runFromMain'
from Main.java:344:in `doRunFromMain'
from Main.java:256:in `internalRun'
from Main.java:222:in `run'
from Main.java:206:in `run'
from Main.java:186:in `main'
```