Created
June 24, 2009 22:11
-
-
Save Serabe/135547 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @JRubyMethod | |
| public IRubyObject native_write_to(ThreadContext context, IRubyObject io, IRubyObject encoding, IRubyObject indentString, IRubyObject options) { | |
| StringWriter sw = new StringWriter(); | |
| try { | |
| Transformer t = TransformerFactory.newInstance().newTransformer(); | |
| t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); | |
| t.transform(new DOMSource(this.node), new StreamResult(sw)); | |
| } catch (TransformerException te) { | |
| throw context.getRuntime().newRuntimeError("couldn't transform the node back to string"); | |
| } | |
| RuntimeHelpers.invoke(context, io, "write", context.getRuntime().newString(sw.toString())); | |
| return io; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * call-seq: | |
| * native_write_to(io, encoding, options) | |
| * | |
| * Write this Node to +io+ with +encoding+ and +options+ | |
| */ | |
| static VALUE native_write_to( | |
| VALUE self, | |
| VALUE io, | |
| VALUE encoding, | |
| VALUE indent_string, | |
| VALUE options | |
| ) { | |
| xmlNodePtr node; | |
| Data_Get_Struct(self, xmlNode, node); | |
| xmlIndentTreeOutput = 1; | |
| xmlTreeIndentString = StringValuePtr(indent_string); | |
| xmlSaveCtxtPtr savectx = xmlSaveToIO( | |
| (xmlOutputWriteCallback)io_write_callback, | |
| (xmlOutputCloseCallback)io_close_callback, | |
| (void *)io, | |
| RTEST(encoding) ? StringValuePtr(encoding) : NULL, | |
| NUM2INT(options) | |
| ); | |
| xmlSaveTree(savectx, node); | |
| xmlSaveClose(savectx); | |
| return io; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment