libxml-ruby 5.0.3-x64-mingw-ucrt → 5.0.4-x64-mingw-ucrt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY +9 -2
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +1124 -1138
- data/lib/3.4/libxml_ruby.so +0 -0
- data/libxml-ruby.gemspec +1 -0
- data/test/test_sax_parser.rb +25 -6
- metadata +18 -7
| @@ -1,1138 +1,1124 @@ | |
| 1 | 
            -
            #include "ruby_libxml.h"
         | 
| 2 | 
            -
            #include "ruby_xml_writer.h"
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            #ifdef LIBXML_WRITER_ENABLED
         | 
| 5 | 
            -
            #include <libxml/xmlwriter.h>
         | 
| 6 | 
            -
            #endif
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            VALUE cXMLWriter;
         | 
| 9 | 
            -
            static VALUE sEncoding, sStandalone;
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            #ifdef LIBXML_WRITER_ENABLED
         | 
| 12 | 
            -
             | 
| 13 | 
            -
            /*
         | 
| 14 | 
            -
             * Document-class: LibXML::XML::Writer
         | 
| 15 | 
            -
             *
         | 
| 16 | 
            -
             * The XML::Writer class provides a simpler, alternative way to build a valid
         | 
| 17 | 
            -
             * XML document from scratch (forward-only) compared to a DOM approach (based
         | 
| 18 | 
            -
             * on XML::Document class).
         | 
| 19 | 
            -
             *
         | 
| 20 | 
            -
             * For a more in depth tutorial, albeit in C, see http://xmlsoft.org/xmlwriter.html
         | 
| 21 | 
            -
             */
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            #include <libxml/xmlwriter.h>
         | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
            typedef enum
         | 
| 27 | 
            -
            {
         | 
| 28 | 
            -
                RXMLW_OUTPUT_NONE,
         | 
| 29 | 
            -
                RXMLW_OUTPUT_IO,
         | 
| 30 | 
            -
                RXMLW_OUTPUT_DOC,
         | 
| 31 | 
            -
                RXMLW_OUTPUT_STRING
         | 
| 32 | 
            -
            } rxmlw_output_type;
         | 
| 33 | 
            -
             | 
| 34 | 
            -
            typedef struct
         | 
| 35 | 
            -
            {
         | 
| 36 | 
            -
                VALUE output;
         | 
| 37 | 
            -
                rb_encoding* encoding;
         | 
| 38 | 
            -
                xmlBufferPtr buffer;
         | 
| 39 | 
            -
                xmlTextWriterPtr writer;
         | 
| 40 | 
            -
                rxmlw_output_type output_type;
         | 
| 41 | 
            -
                int closed;
         | 
| 42 | 
            -
            } rxml_writer_object;
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            static void rxml_writer_free(rxml_writer_object* rwo)
         | 
| 45 | 
            -
            {
         | 
| 46 | 
            -
            #if 0 /* seems to be done by xmlFreeTextWriter */
         | 
| 47 | 
            -
                if (NULL != rwo->buffer)
         | 
| 48 | 
            -
                {
         | 
| 49 | 
            -
                    xmlBufferFree(rwo->buffer);
         | 
| 50 | 
            -
                }
         | 
| 51 | 
            -
            #endif
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                rwo->closed = 1;
         | 
| 54 | 
            -
                xmlFreeTextWriter(rwo->writer);
         | 
| 55 | 
            -
                xfree(rwo);
         | 
| 56 | 
            -
            }
         | 
| 57 | 
            -
             | 
| 58 | 
            -
            static void rxml_writer_mark(rxml_writer_object* rwo)
         | 
| 59 | 
            -
            {
         | 
| 60 | 
            -
                if (!NIL_P(rwo->output))
         | 
| 61 | 
            -
                {
         | 
| 62 | 
            -
                    rb_gc_mark(rwo->output);
         | 
| 63 | 
            -
                }
         | 
| 64 | 
            -
            }
         | 
| 65 | 
            -
             | 
| 66 | 
            -
            static VALUE rxml_writer_wrap(rxml_writer_object* rwo)
         | 
| 67 | 
            -
            {
         | 
| 68 | 
            -
                return Data_Wrap_Struct(cXMLWriter, rxml_writer_mark, rxml_writer_free, rwo);
         | 
| 69 | 
            -
            }
         | 
| 70 | 
            -
             | 
| 71 | 
            -
            static rxml_writer_object* rxml_textwriter_get(VALUE obj)
         | 
| 72 | 
            -
            {
         | 
| 73 | 
            -
                rxml_writer_object* rwo;
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                Data_Get_Struct(obj, rxml_writer_object, rwo);
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                return rwo;
         | 
| 78 | 
            -
            }
         | 
| 79 | 
            -
             | 
| 80 | 
            -
            int rxml_writer_write_callback(void* context, const char* buffer, int len)
         | 
| 81 | 
            -
            {
         | 
| 82 | 
            -
                rxml_writer_object* rwo = context;
         | 
| 83 | 
            -
             | 
| 84 | 
            -
                if (rwo->closed)
         | 
| 85 | 
            -
                {
         | 
| 86 | 
            -
                    return 0;
         | 
| 87 | 
            -
                }
         | 
| 88 | 
            -
                else
         | 
| 89 | 
            -
                {
         | 
| 90 | 
            -
                    return rxml_write_callback(rwo->output, buffer, len);
         | 
| 91 | 
            -
                }
         | 
| 92 | 
            -
            }
         | 
| 93 | 
            -
             | 
| 94 | 
            -
            /* ===== public class methods ===== */
         | 
| 95 | 
            -
             | 
| 96 | 
            -
            /* call-seq:
         | 
| 97 | 
            -
             *    XML::Writer::io(io) -> XML::Writer
         | 
| 98 | 
            -
             *
         | 
| 99 | 
            -
             * Creates a XML::Writer which will write XML directly into an IO object.
         | 
| 100 | 
            -
             */
         | 
| 101 | 
            -
            static VALUE rxml_writer_io(VALUE klass, VALUE io)
         | 
| 102 | 
            -
            {
         | 
| 103 | 
            -
                xmlOutputBufferPtr out;
         | 
| 104 | 
            -
                rxml_writer_object* rwo;
         | 
| 105 | 
            -
             | 
| 106 | 
            -
                rwo = ALLOC(rxml_writer_object);
         | 
| 107 | 
            -
                rwo->output = io;
         | 
| 108 | 
            -
                rwo->buffer = NULL;
         | 
| 109 | 
            -
                rwo->closed = 0;
         | 
| 110 | 
            -
                rwo->encoding = rb_enc_get(io);
         | 
| 111 | 
            -
                if (!rwo->encoding)
         | 
| 112 | 
            -
                    rwo->encoding = rb_utf8_encoding();
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                rwo->output_type = RXMLW_OUTPUT_IO;
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name);
         | 
| 117 | 
            -
                if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr)))
         | 
| 118 | 
            -
                {
         | 
| 119 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 120 | 
            -
                }
         | 
| 121 | 
            -
                if (NULL == (rwo->writer = xmlNewTextWriter(out)))
         | 
| 122 | 
            -
                {
         | 
| 123 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 124 | 
            -
                }
         | 
| 125 | 
            -
             | 
| 126 | 
            -
                return rxml_writer_wrap(rwo);
         | 
| 127 | 
            -
            }
         | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
            /* call-seq:
         | 
| 131 | 
            -
             *    XML::Writer::file(path) -> XML::Writer
         | 
| 132 | 
            -
             *
         | 
| 133 | 
            -
             * Creates a XML::Writer object which will write XML into the file with
         | 
| 134 | 
            -
             * the given name.
         | 
| 135 | 
            -
             */
         | 
| 136 | 
            -
            static VALUE rxml_writer_file(VALUE klass, VALUE filename)
         | 
| 137 | 
            -
            {
         | 
| 138 | 
            -
                rxml_writer_object* rwo;
         | 
| 139 | 
            -
             | 
| 140 | 
            -
                rwo = ALLOC(rxml_writer_object);
         | 
| 141 | 
            -
                rwo->output = Qnil;
         | 
| 142 | 
            -
                rwo->buffer = NULL;
         | 
| 143 | 
            -
                rwo->closed = 0;
         | 
| 144 | 
            -
                rwo->encoding = rb_utf8_encoding();
         | 
| 145 | 
            -
                rwo->output_type = RXMLW_OUTPUT_NONE;
         | 
| 146 | 
            -
                if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
         | 
| 147 | 
            -
                {
         | 
| 148 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 149 | 
            -
                }
         | 
| 150 | 
            -
             | 
| 151 | 
            -
                return rxml_writer_wrap(rwo);
         | 
| 152 | 
            -
            }
         | 
| 153 | 
            -
             | 
| 154 | 
            -
            /* call-seq:
         | 
| 155 | 
            -
             *    XML::Writer::string -> XML::Writer
         | 
| 156 | 
            -
             *
         | 
| 157 | 
            -
             * Creates a XML::Writer which will write XML into memory, as string.
         | 
| 158 | 
            -
             */
         | 
| 159 | 
            -
            static VALUE rxml_writer_string(VALUE klass)
         | 
| 160 | 
            -
            {
         | 
| 161 | 
            -
                rxml_writer_object* rwo;
         | 
| 162 | 
            -
             | 
| 163 | 
            -
                rwo = ALLOC(rxml_writer_object);
         | 
| 164 | 
            -
                rwo->output = Qnil;
         | 
| 165 | 
            -
                rwo->closed = 0;
         | 
| 166 | 
            -
                rwo->encoding = rb_utf8_encoding();
         | 
| 167 | 
            -
                rwo->output_type = RXMLW_OUTPUT_STRING;
         | 
| 168 | 
            -
                if (NULL == (rwo->buffer = xmlBufferCreate()))
         | 
| 169 | 
            -
                {
         | 
| 170 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 171 | 
            -
                }
         | 
| 172 | 
            -
                if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
         | 
| 173 | 
            -
                {
         | 
| 174 | 
            -
                    xmlBufferFree(rwo->buffer);
         | 
| 175 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 176 | 
            -
                }
         | 
| 177 | 
            -
             | 
| 178 | 
            -
                return rxml_writer_wrap(rwo);
         | 
| 179 | 
            -
            }
         | 
| 180 | 
            -
             | 
| 181 | 
            -
            /* call-seq:
         | 
| 182 | 
            -
             *    XML::Writer::document -> XML::Writer
         | 
| 183 | 
            -
             *
         | 
| 184 | 
            -
             * Creates a XML::Writer which will write into an in memory XML::Document
         | 
| 185 | 
            -
             */
         | 
| 186 | 
            -
            static VALUE rxml_writer_doc(VALUE klass)
         | 
| 187 | 
            -
            {
         | 
| 188 | 
            -
                xmlDocPtr doc;
         | 
| 189 | 
            -
                rxml_writer_object* rwo;
         | 
| 190 | 
            -
             | 
| 191 | 
            -
                rwo = ALLOC(rxml_writer_object);
         | 
| 192 | 
            -
                rwo->buffer = NULL;
         | 
| 193 | 
            -
                rwo->output = Qnil;
         | 
| 194 | 
            -
                rwo->closed = 0;
         | 
| 195 | 
            -
                rwo->encoding = rb_utf8_encoding();
         | 
| 196 | 
            -
                rwo->output_type = RXMLW_OUTPUT_DOC;
         | 
| 197 | 
            -
                if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
         | 
| 198 | 
            -
                {
         | 
| 199 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 200 | 
            -
                }
         | 
| 201 | 
            -
                rwo->output = rxml_document_wrap(doc);
         | 
| 202 | 
            -
             | 
| 203 | 
            -
                return rxml_writer_wrap(rwo);
         | 
| 204 | 
            -
            }
         | 
| 205 | 
            -
             | 
| 206 | 
            -
            /* ===== public instance methods ===== */
         | 
| 207 | 
            -
             | 
| 208 | 
            -
            /* call-seq:
         | 
| 209 | 
            -
             *    writer.flush(empty? = true) -> (num|string)
         | 
| 210 | 
            -
             *
         | 
| 211 | 
            -
             * Flushes the output buffer. Returns the number of written bytes or
         | 
| 212 | 
            -
             * the current content of the internal buffer for a in memory XML::Writer.
         | 
| 213 | 
            -
             * If +empty?+ is +true+, and for a in memory XML::Writer, this internel
         | 
| 214 | 
            -
             * buffer is empty.
         | 
| 215 | 
            -
             */
         | 
| 216 | 
            -
            static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self)
         | 
| 217 | 
            -
            {
         | 
| 218 | 
            -
                int ret;
         | 
| 219 | 
            -
                VALUE empty;
         | 
| 220 | 
            -
                rxml_writer_object* rwo;
         | 
| 221 | 
            -
             | 
| 222 | 
            -
                rb_scan_args(argc, argv, "01", &empty);
         | 
| 223 | 
            -
             | 
| 224 | 
            -
                rwo = rxml_textwriter_get(self);
         | 
| 225 | 
            -
                if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
         | 
| 226 | 
            -
                {
         | 
| 227 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 228 | 
            -
                }
         | 
| 229 | 
            -
             | 
| 230 | 
            -
                if (NULL != rwo->buffer)
         | 
| 231 | 
            -
                {
         | 
| 232 | 
            -
                    VALUE content;
         | 
| 233 | 
            -
             | 
| 234 | 
            -
                    content = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
         | 
| 235 | 
            -
                    if (NIL_P(empty) || RTEST(empty))
         | 
| 236 | 
            -
                    { /* nil = default value = true */
         | 
| 237 | 
            -
                        xmlBufferEmpty(rwo->buffer);
         | 
| 238 | 
            -
                    }
         | 
| 239 | 
            -
             | 
| 240 | 
            -
                    return content;
         | 
| 241 | 
            -
                }
         | 
| 242 | 
            -
                else
         | 
| 243 | 
            -
                {
         | 
| 244 | 
            -
                    return INT2NUM(ret);
         | 
| 245 | 
            -
                }
         | 
| 246 | 
            -
            }
         | 
| 247 | 
            -
             | 
| 248 | 
            -
            /* call-seq:
         | 
| 249 | 
            -
             *    writer.result -> (XML::Document|"string"|nil)
         | 
| 250 | 
            -
             *
         | 
| 251 | 
            -
             * Returns the associated result object to the XML::Writer creation.
         | 
| 252 | 
            -
             * A String for a XML::Writer object created with XML::Writer::string,
         | 
| 253 | 
            -
             * a XML::Document with XML::Writer::document, etc.
         | 
| 254 | 
            -
             */
         | 
| 255 | 
            -
            static VALUE rxml_writer_result(VALUE self)
         | 
| 256 | 
            -
            {
         | 
| 257 | 
            -
                VALUE ret = Qnil;
         | 
| 258 | 
            -
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 259 | 
            -
                int bytesWritten = xmlTextWriterFlush(rwo->writer);
         | 
| 260 | 
            -
             | 
| 261 | 
            -
                if (bytesWritten == -1)
         | 
| 262 | 
            -
                {
         | 
| 263 | 
            -
                    rxml_raise(xmlGetLastError());
         | 
| 264 | 
            -
                }
         | 
| 265 | 
            -
             | 
| 266 | 
            -
                switch (rwo->output_type)
         | 
| 267 | 
            -
                {
         | 
| 268 | 
            -
                case RXMLW_OUTPUT_DOC:
         | 
| 269 | 
            -
                    ret = rwo->output;
         | 
| 270 | 
            -
                    break;
         | 
| 271 | 
            -
                case RXMLW_OUTPUT_STRING:
         | 
| 272 | 
            -
                    ret = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
         | 
| 273 | 
            -
                    break;
         | 
| 274 | 
            -
                case RXMLW_OUTPUT_IO:
         | 
| 275 | 
            -
                case RXMLW_OUTPUT_NONE:
         | 
| 276 | 
            -
                    break;
         | 
| 277 | 
            -
                default:
         | 
| 278 | 
            -
                    rb_bug("unexpected output");
         | 
| 279 | 
            -
                    break;
         | 
| 280 | 
            -
                }
         | 
| 281 | 
            -
             | 
| 282 | 
            -
                return ret;
         | 
| 283 | 
            -
            }
         | 
| 284 | 
            -
             | 
| 285 | 
            -
            /* ===== private helpers ===== */
         | 
| 286 | 
            -
             | 
| 287 | 
            -
             | 
| 288 | 
            -
             | 
| 289 | 
            -
                 | 
| 290 | 
            -
             | 
| 291 | 
            -
             | 
| 292 | 
            -
             | 
| 293 | 
            -
             | 
| 294 | 
            -
             | 
| 295 | 
            -
             | 
| 296 | 
            -
             | 
| 297 | 
            -
             | 
| 298 | 
            -
             | 
| 299 | 
            -
             | 
| 300 | 
            -
             | 
| 301 | 
            -
             | 
| 302 | 
            -
             | 
| 303 | 
            -
             | 
| 304 | 
            -
              | 
| 305 | 
            -
             | 
| 306 | 
            -
             | 
| 307 | 
            -
              | 
| 308 | 
            -
              | 
| 309 | 
            -
             | 
| 310 | 
            -
             | 
| 311 | 
            -
             | 
| 312 | 
            -
             | 
| 313 | 
            -
                 | 
| 314 | 
            -
             | 
| 315 | 
            -
                 | 
| 316 | 
            -
                const xmlChar*  | 
| 317 | 
            -
                VALUE  | 
| 318 | 
            -
             | 
| 319 | 
            -
                 | 
| 320 | 
            -
                 | 
| 321 | 
            -
             | 
| 322 | 
            -
             | 
| 323 | 
            -
             | 
| 324 | 
            -
             | 
| 325 | 
            -
             | 
| 326 | 
            -
             | 
| 327 | 
            -
             | 
| 328 | 
            -
             | 
| 329 | 
            -
             | 
| 330 | 
            -
             | 
| 331 | 
            -
             | 
| 332 | 
            -
             | 
| 333 | 
            -
             | 
| 334 | 
            -
             | 
| 335 | 
            -
             | 
| 336 | 
            -
             | 
| 337 | 
            -
             | 
| 338 | 
            -
             | 
| 339 | 
            -
             | 
| 340 | 
            -
             | 
| 341 | 
            -
             | 
| 342 | 
            -
                 | 
| 343 | 
            -
             | 
| 344 | 
            -
             | 
| 345 | 
            -
             | 
| 346 | 
            -
             | 
| 347 | 
            -
             | 
| 348 | 
            -
             | 
| 349 | 
            -
             | 
| 350 | 
            -
             | 
| 351 | 
            -
             | 
| 352 | 
            -
             | 
| 353 | 
            -
             | 
| 354 | 
            -
             | 
| 355 | 
            -
             | 
| 356 | 
            -
             | 
| 357 | 
            -
             | 
| 358 | 
            -
             | 
| 359 | 
            -
             | 
| 360 | 
            -
             | 
| 361 | 
            -
             | 
| 362 | 
            -
             | 
| 363 | 
            -
             | 
| 364 | 
            -
             | 
| 365 | 
            -
             | 
| 366 | 
            -
             | 
| 367 | 
            -
             | 
| 368 | 
            -
             | 
| 369 | 
            -
             | 
| 370 | 
            -
             | 
| 371 | 
            -
             | 
| 372 | 
            -
             | 
| 373 | 
            -
             | 
| 374 | 
            -
             | 
| 375 | 
            -
             | 
| 376 | 
            -
             | 
| 377 | 
            -
             | 
| 378 | 
            -
             | 
| 379 | 
            -
             | 
| 380 | 
            -
             | 
| 381 | 
            -
             | 
| 382 | 
            -
             | 
| 383 | 
            -
             | 
| 384 | 
            -
             | 
| 385 | 
            -
             | 
| 386 | 
            -
             | 
| 387 | 
            -
             | 
| 388 | 
            -
             | 
| 389 | 
            -
             | 
| 390 | 
            -
             | 
| 391 | 
            -
             | 
| 392 | 
            -
             | 
| 393 | 
            -
             | 
| 394 | 
            -
             | 
| 395 | 
            -
             | 
| 396 | 
            -
             | 
| 397 | 
            -
             | 
| 398 | 
            -
             | 
| 399 | 
            -
             | 
| 400 | 
            -
             | 
| 401 | 
            -
                 | 
| 402 | 
            -
             | 
| 403 | 
            -
             | 
| 404 | 
            -
             | 
| 405 | 
            -
             | 
| 406 | 
            -
             | 
| 407 | 
            -
             | 
| 408 | 
            -
                     | 
| 409 | 
            -
                }
         | 
| 410 | 
            -
             | 
| 411 | 
            -
                 | 
| 412 | 
            -
             | 
| 413 | 
            -
             | 
| 414 | 
            -
             | 
| 415 | 
            -
             | 
| 416 | 
            -
             | 
| 417 | 
            -
             | 
| 418 | 
            -
              | 
| 419 | 
            -
             | 
| 420 | 
            -
             | 
| 421 | 
            -
             | 
| 422 | 
            -
              | 
| 423 | 
            -
              | 
| 424 | 
            -
             | 
| 425 | 
            -
             | 
| 426 | 
            -
                 | 
| 427 | 
            -
             | 
| 428 | 
            -
             | 
| 429 | 
            -
             | 
| 430 | 
            -
             | 
| 431 | 
            -
             | 
| 432 | 
            -
             | 
| 433 | 
            -
             | 
| 434 | 
            -
             | 
| 435 | 
            -
             | 
| 436 | 
            -
             * | 
| 437 | 
            -
             *
         | 
| 438 | 
            -
              | 
| 439 | 
            -
              | 
| 440 | 
            -
             | 
| 441 | 
            -
              | 
| 442 | 
            -
             | 
| 443 | 
            -
              | 
| 444 | 
            -
             | 
| 445 | 
            -
            {
         | 
| 446 | 
            -
             | 
| 447 | 
            -
             | 
| 448 | 
            -
             | 
| 449 | 
            -
             | 
| 450 | 
            -
             | 
| 451 | 
            -
             | 
| 452 | 
            -
             | 
| 453 | 
            -
             | 
| 454 | 
            -
             | 
| 455 | 
            -
             | 
| 456 | 
            -
              | 
| 457 | 
            -
              | 
| 458 | 
            -
             *  | 
| 459 | 
            -
              | 
| 460 | 
            -
             | 
| 461 | 
            -
             | 
| 462 | 
            -
                 | 
| 463 | 
            -
            }
         | 
| 464 | 
            -
             | 
| 465 | 
            -
            /* call-seq:
         | 
| 466 | 
            -
             *    writer. | 
| 467 | 
            -
             *
         | 
| 468 | 
            -
             * Writes a full  | 
| 469 | 
            -
             *  | 
| 470 | 
            -
             */
         | 
| 471 | 
            -
            static VALUE  | 
| 472 | 
            -
            {
         | 
| 473 | 
            -
                 | 
| 474 | 
            -
            }
         | 
| 475 | 
            -
             | 
| 476 | 
            -
             | 
| 477 | 
            -
             | 
| 478 | 
            -
             | 
| 479 | 
            -
             | 
| 480 | 
            -
             | 
| 481 | 
            -
              | 
| 482 | 
            -
             *
         | 
| 483 | 
            -
             * | 
| 484 | 
            -
             *  | 
| 485 | 
            -
             *  | 
| 486 | 
            -
              | 
| 487 | 
            -
             | 
| 488 | 
            -
             | 
| 489 | 
            -
             | 
| 490 | 
            -
             | 
| 491 | 
            -
             | 
| 492 | 
            -
             | 
| 493 | 
            -
             | 
| 494 | 
            -
             | 
| 495 | 
            -
             | 
| 496 | 
            -
             | 
| 497 | 
            -
             | 
| 498 | 
            -
             | 
| 499 | 
            -
             | 
| 500 | 
            -
                 | 
| 501 | 
            -
                {
         | 
| 502 | 
            -
             | 
| 503 | 
            -
                 | 
| 504 | 
            -
             | 
| 505 | 
            -
             | 
| 506 | 
            -
             | 
| 507 | 
            -
             | 
| 508 | 
            -
             | 
| 509 | 
            -
             | 
| 510 | 
            -
             * | 
| 511 | 
            -
             *
         | 
| 512 | 
            -
             *  | 
| 513 | 
            -
              | 
| 514 | 
            -
              | 
| 515 | 
            -
             | 
| 516 | 
            -
             | 
| 517 | 
            -
              | 
| 518 | 
            -
             *  | 
| 519 | 
            -
              | 
| 520 | 
            -
              | 
| 521 | 
            -
              | 
| 522 | 
            -
             | 
| 523 | 
            -
             | 
| 524 | 
            -
             | 
| 525 | 
            -
             | 
| 526 | 
            -
             | 
| 527 | 
            -
                 | 
| 528 | 
            -
             | 
| 529 | 
            -
             | 
| 530 | 
            -
             | 
| 531 | 
            -
             | 
| 532 | 
            -
             | 
| 533 | 
            -
             | 
| 534 | 
            -
             | 
| 535 | 
            -
             | 
| 536 | 
            -
             | 
| 537 | 
            -
             | 
| 538 | 
            -
             | 
| 539 | 
            -
                 | 
| 540 | 
            -
             | 
| 541 | 
            -
             | 
| 542 | 
            -
             | 
| 543 | 
            -
             | 
| 544 | 
            -
             | 
| 545 | 
            -
              | 
| 546 | 
            -
             | 
| 547 | 
            -
              | 
| 548 | 
            -
             | 
| 549 | 
            -
             | 
| 550 | 
            -
             | 
| 551 | 
            -
             | 
| 552 | 
            -
             | 
| 553 | 
            -
             | 
| 554 | 
            -
             | 
| 555 | 
            -
             | 
| 556 | 
            -
             | 
| 557 | 
            -
              | 
| 558 | 
            -
             | 
| 559 | 
            -
             | 
| 560 | 
            -
              | 
| 561 | 
            -
             *
         | 
| 562 | 
            -
             * | 
| 563 | 
            -
             *  | 
| 564 | 
            -
             * | 
| 565 | 
            -
             *  | 
| 566 | 
            -
             *  | 
| 567 | 
            -
             *  | 
| 568 | 
            -
              | 
| 569 | 
            -
             | 
| 570 | 
            -
             | 
| 571 | 
            -
             | 
| 572 | 
            -
             | 
| 573 | 
            -
                rb_scan_args(argc, argv, " | 
| 574 | 
            -
             | 
| 575 | 
            -
                 | 
| 576 | 
            -
            }
         | 
| 577 | 
            -
             | 
| 578 | 
            -
             | 
| 579 | 
            -
              | 
| 580 | 
            -
              | 
| 581 | 
            -
             | 
| 582 | 
            -
             | 
| 583 | 
            -
              | 
| 584 | 
            -
             | 
| 585 | 
            -
             | 
| 586 | 
            -
             | 
| 587 | 
            -
             | 
| 588 | 
            -
             | 
| 589 | 
            -
             | 
| 590 | 
            -
             | 
| 591 | 
            -
             | 
| 592 | 
            -
             | 
| 593 | 
            -
              | 
| 594 | 
            -
              | 
| 595 | 
            -
             *  | 
| 596 | 
            -
             * | 
| 597 | 
            -
              | 
| 598 | 
            -
             | 
| 599 | 
            -
             | 
| 600 | 
            -
             | 
| 601 | 
            -
             | 
| 602 | 
            -
             | 
| 603 | 
            -
             | 
| 604 | 
            -
             | 
| 605 | 
            -
              | 
| 606 | 
            -
             *  | 
| 607 | 
            -
             * | 
| 608 | 
            -
             *  | 
| 609 | 
            -
              | 
| 610 | 
            -
             | 
| 611 | 
            -
             | 
| 612 | 
            -
             | 
| 613 | 
            -
             | 
| 614 | 
            -
             | 
| 615 | 
            -
            /*  | 
| 616 | 
            -
             | 
| 617 | 
            -
              | 
| 618 | 
            -
             * | 
| 619 | 
            -
              | 
| 620 | 
            -
             | 
| 621 | 
            -
             | 
| 622 | 
            -
             | 
| 623 | 
            -
             | 
| 624 | 
            -
             | 
| 625 | 
            -
             | 
| 626 | 
            -
             | 
| 627 | 
            -
              | 
| 628 | 
            -
             *  | 
| 629 | 
            -
             *
         | 
| 630 | 
            -
             *  | 
| 631 | 
            -
             * | 
| 632 | 
            -
             *  | 
| 633 | 
            -
             * prefix  | 
| 634 | 
            -
              | 
| 635 | 
            -
             | 
| 636 | 
            -
             | 
| 637 | 
            -
             | 
| 638 | 
            -
             | 
| 639 | 
            -
                 | 
| 640 | 
            -
             | 
| 641 | 
            -
             | 
| 642 | 
            -
             | 
| 643 | 
            -
             | 
| 644 | 
            -
             | 
| 645 | 
            -
             | 
| 646 | 
            -
              | 
| 647 | 
            -
              | 
| 648 | 
            -
             | 
| 649 | 
            -
             | 
| 650 | 
            -
             | 
| 651 | 
            -
                 | 
| 652 | 
            -
             | 
| 653 | 
            -
             | 
| 654 | 
            -
             | 
| 655 | 
            -
             | 
| 656 | 
            -
             | 
| 657 | 
            -
              | 
| 658 | 
            -
             | 
| 659 | 
            -
             | 
| 660 | 
            -
              | 
| 661 | 
            -
             | 
| 662 | 
            -
             | 
| 663 | 
            -
             | 
| 664 | 
            -
             | 
| 665 | 
            -
             | 
| 666 | 
            -
             | 
| 667 | 
            -
              | 
| 668 | 
            -
             | 
| 669 | 
            -
              | 
| 670 | 
            -
             | 
| 671 | 
            -
             | 
| 672 | 
            -
             | 
| 673 | 
            -
             | 
| 674 | 
            -
             | 
| 675 | 
            -
             | 
| 676 | 
            -
             | 
| 677 | 
            -
             | 
| 678 | 
            -
             | 
| 679 | 
            -
              | 
| 680 | 
            -
             | 
| 681 | 
            -
             | 
| 682 | 
            -
              | 
| 683 | 
            -
             | 
| 684 | 
            -
             | 
| 685 | 
            -
             | 
| 686 | 
            -
             | 
| 687 | 
            -
             | 
| 688 | 
            -
             | 
| 689 | 
            -
              | 
| 690 | 
            -
             | 
| 691 | 
            -
             | 
| 692 | 
            -
              | 
| 693 | 
            -
             *  | 
| 694 | 
            -
             * | 
| 695 | 
            -
             *  | 
| 696 | 
            -
             * | 
| 697 | 
            -
              | 
| 698 | 
            -
             | 
| 699 | 
            -
             | 
| 700 | 
            -
             | 
| 701 | 
            -
             | 
| 702 | 
            -
             | 
| 703 | 
            -
             | 
| 704 | 
            -
             | 
| 705 | 
            -
             | 
| 706 | 
            -
             | 
| 707 | 
            -
             | 
| 708 | 
            -
             | 
| 709 | 
            -
              | 
| 710 | 
            -
             | 
| 711 | 
            -
              | 
| 712 | 
            -
             | 
| 713 | 
            -
             | 
| 714 | 
            -
                 | 
| 715 | 
            -
             | 
| 716 | 
            -
             | 
| 717 | 
            -
             | 
| 718 | 
            -
             | 
| 719 | 
            -
              | 
| 720 | 
            -
             | 
| 721 | 
            -
              | 
| 722 | 
            -
              | 
| 723 | 
            -
              | 
| 724 | 
            -
             | 
| 725 | 
            -
            {
         | 
| 726 | 
            -
             | 
| 727 | 
            -
            }
         | 
| 728 | 
            -
             | 
| 729 | 
            -
             | 
| 730 | 
            -
              | 
| 731 | 
            -
             | 
| 732 | 
            -
             | 
| 733 | 
            -
              | 
| 734 | 
            -
             | 
| 735 | 
            -
             | 
| 736 | 
            -
             | 
| 737 | 
            -
             | 
| 738 | 
            -
             | 
| 739 | 
            -
             | 
| 740 | 
            -
              | 
| 741 | 
            -
             *
         | 
| 742 | 
            -
             * | 
| 743 | 
            -
              | 
| 744 | 
            -
             | 
| 745 | 
            -
             | 
| 746 | 
            -
             | 
| 747 | 
            -
             | 
| 748 | 
            -
             | 
| 749 | 
            -
             | 
| 750 | 
            -
              | 
| 751 | 
            -
             *    writer. | 
| 752 | 
            -
             * | 
| 753 | 
            -
             *
         | 
| 754 | 
            -
              | 
| 755 | 
            -
              | 
| 756 | 
            -
             | 
| 757 | 
            -
              | 
| 758 | 
            -
             | 
| 759 | 
            -
             | 
| 760 | 
            -
              | 
| 761 | 
            -
             *  | 
| 762 | 
            -
              | 
| 763 | 
            -
             | 
| 764 | 
            -
             | 
| 765 | 
            -
             | 
| 766 | 
            -
             | 
| 767 | 
            -
                 | 
| 768 | 
            -
             | 
| 769 | 
            -
             | 
| 770 | 
            -
             | 
| 771 | 
            -
                 | 
| 772 | 
            -
             | 
| 773 | 
            -
             | 
| 774 | 
            -
             | 
| 775 | 
            -
             | 
| 776 | 
            -
             | 
| 777 | 
            -
             | 
| 778 | 
            -
             | 
| 779 | 
            -
             | 
| 780 | 
            -
             | 
| 781 | 
            -
             | 
| 782 | 
            -
             | 
| 783 | 
            -
             | 
| 784 | 
            -
             | 
| 785 | 
            -
             | 
| 786 | 
            -
             | 
| 787 | 
            -
             | 
| 788 | 
            -
             | 
| 789 | 
            -
                 | 
| 790 | 
            -
             | 
| 791 | 
            -
             | 
| 792 | 
            -
             | 
| 793 | 
            -
             | 
| 794 | 
            -
             | 
| 795 | 
            -
             | 
| 796 | 
            -
             | 
| 797 | 
            -
             | 
| 798 | 
            -
              | 
| 799 | 
            -
             *
         | 
| 800 | 
            -
             * | 
| 801 | 
            -
              | 
| 802 | 
            -
             | 
| 803 | 
            -
             | 
| 804 | 
            -
             | 
| 805 | 
            -
             | 
| 806 | 
            -
             | 
| 807 | 
            -
             | 
| 808 | 
            -
             | 
| 809 | 
            -
              | 
| 810 | 
            -
             *  | 
| 811 | 
            -
              | 
| 812 | 
            -
             | 
| 813 | 
            -
             | 
| 814 | 
            -
             | 
| 815 | 
            -
             | 
| 816 | 
            -
             | 
| 817 | 
            -
             | 
| 818 | 
            -
             * | 
| 819 | 
            -
             *
         | 
| 820 | 
            -
              | 
| 821 | 
            -
              | 
| 822 | 
            -
             | 
| 823 | 
            -
             | 
| 824 | 
            -
             | 
| 825 | 
            -
             | 
| 826 | 
            -
             | 
| 827 | 
            -
             | 
| 828 | 
            -
             * | 
| 829 | 
            -
             *
         | 
| 830 | 
            -
              | 
| 831 | 
            -
              | 
| 832 | 
            -
             | 
| 833 | 
            -
             | 
| 834 | 
            -
             | 
| 835 | 
            -
             | 
| 836 | 
            -
             | 
| 837 | 
            -
             | 
| 838 | 
            -
             | 
| 839 | 
            -
             | 
| 840 | 
            -
             | 
| 841 | 
            -
             | 
| 842 | 
            -
             | 
| 843 | 
            -
              | 
| 844 | 
            -
             | 
| 845 | 
            -
             | 
| 846 | 
            -
             | 
| 847 | 
            -
             | 
| 848 | 
            -
             | 
| 849 | 
            -
             | 
| 850 | 
            -
             | 
| 851 | 
            -
             | 
| 852 | 
            -
             | 
| 853 | 
            -
              | 
| 854 | 
            -
             | 
| 855 | 
            -
             | 
| 856 | 
            -
             | 
| 857 | 
            -
             | 
| 858 | 
            -
             | 
| 859 | 
            -
             | 
| 860 | 
            -
             | 
| 861 | 
            -
             | 
| 862 | 
            -
             | 
| 863 | 
            -
             | 
| 864 | 
            -
             | 
| 865 | 
            -
             | 
| 866 | 
            -
             | 
| 867 | 
            -
             | 
| 868 | 
            -
             | 
| 869 | 
            -
             | 
| 870 | 
            -
             * | 
| 871 | 
            -
             *
         | 
| 872 | 
            -
             *  | 
| 873 | 
            -
              | 
| 874 | 
            -
             | 
| 875 | 
            -
             | 
| 876 | 
            -
             | 
| 877 | 
            -
             | 
| 878 | 
            -
             | 
| 879 | 
            -
             | 
| 880 | 
            -
             * | 
| 881 | 
            -
             *
         | 
| 882 | 
            -
             *  | 
| 883 | 
            -
              | 
| 884 | 
            -
             | 
| 885 | 
            -
             | 
| 886 | 
            -
             | 
| 887 | 
            -
             | 
| 888 | 
            -
             | 
| 889 | 
            -
             | 
| 890 | 
            -
             | 
| 891 | 
            -
              | 
| 892 | 
            -
             *  | 
| 893 | 
            -
              | 
| 894 | 
            -
             | 
| 895 | 
            -
             | 
| 896 | 
            -
             | 
| 897 | 
            -
             | 
| 898 | 
            -
             | 
| 899 | 
            -
             | 
| 900 | 
            -
             * | 
| 901 | 
            -
             *
         | 
| 902 | 
            -
             *  | 
| 903 | 
            -
              | 
| 904 | 
            -
             | 
| 905 | 
            -
             | 
| 906 | 
            -
             | 
| 907 | 
            -
             | 
| 908 | 
            -
             | 
| 909 | 
            -
             | 
| 910 | 
            -
             | 
| 911 | 
            -
              | 
| 912 | 
            -
              | 
| 913 | 
            -
             | 
| 914 | 
            -
             | 
| 915 | 
            -
             | 
| 916 | 
            -
                 | 
| 917 | 
            -
             | 
| 918 | 
            -
             | 
| 919 | 
            -
             | 
| 920 | 
            -
             * | 
| 921 | 
            -
              | 
| 922 | 
            -
              | 
| 923 | 
            -
             | 
| 924 | 
            -
             | 
| 925 | 
            -
              | 
| 926 | 
            -
             *  | 
| 927 | 
            -
              | 
| 928 | 
            -
              | 
| 929 | 
            -
              | 
| 930 | 
            -
             | 
| 931 | 
            -
             | 
| 932 | 
            -
              | 
| 933 | 
            -
             * | 
| 934 | 
            -
             * | 
| 935 | 
            -
             * | 
| 936 | 
            -
              | 
| 937 | 
            -
              | 
| 938 | 
            -
             | 
| 939 | 
            -
             | 
| 940 | 
            -
                VALUE name, pubid, sysid,  | 
| 941 | 
            -
             | 
| 942 | 
            -
                 | 
| 943 | 
            -
             | 
| 944 | 
            -
                return  | 
| 945 | 
            -
            }
         | 
| 946 | 
            -
             | 
| 947 | 
            -
            /* call-seq:
         | 
| 948 | 
            -
             *    writer. | 
| 949 | 
            -
             *
         | 
| 950 | 
            -
             * Writes a DTD  | 
| 951 | 
            -
             * | 
| 952 | 
            -
             * | 
| 953 | 
            -
              | 
| 954 | 
            -
             | 
| 955 | 
            -
             | 
| 956 | 
            -
             | 
| 957 | 
            -
             | 
| 958 | 
            -
             | 
| 959 | 
            -
             | 
| 960 | 
            -
             | 
| 961 | 
            -
              | 
| 962 | 
            -
              | 
| 963 | 
            -
             * | 
| 964 | 
            -
              | 
| 965 | 
            -
              | 
| 966 | 
            -
             | 
| 967 | 
            -
             | 
| 968 | 
            -
             | 
| 969 | 
            -
             | 
| 970 | 
            -
             | 
| 971 | 
            -
             | 
| 972 | 
            -
             * | 
| 973 | 
            -
              | 
| 974 | 
            -
              | 
| 975 | 
            -
             | 
| 976 | 
            -
             | 
| 977 | 
            -
            {
         | 
| 978 | 
            -
                 | 
| 979 | 
            -
             | 
| 980 | 
            -
             | 
| 981 | 
            -
             | 
| 982 | 
            -
             | 
| 983 | 
            -
             | 
| 984 | 
            -
              | 
| 985 | 
            -
             *  | 
| 986 | 
            -
             * | 
| 987 | 
            -
             *  | 
| 988 | 
            -
             * | 
| 989 | 
            -
             *  | 
| 990 | 
            -
             *  | 
| 991 | 
            -
             *  | 
| 992 | 
            -
              | 
| 993 | 
            -
             | 
| 994 | 
            -
             | 
| 995 | 
            -
             | 
| 996 | 
            -
             | 
| 997 | 
            -
             | 
| 998 | 
            -
             | 
| 999 | 
            -
             * | 
| 1000 | 
            -
              | 
| 1001 | 
            -
              | 
| 1002 | 
            -
              | 
| 1003 | 
            -
             | 
| 1004 | 
            -
             | 
| 1005 | 
            -
             | 
| 1006 | 
            -
             | 
| 1007 | 
            -
             | 
| 1008 | 
            -
             | 
| 1009 | 
            -
              | 
| 1010 | 
            -
              | 
| 1011 | 
            -
             | 
| 1012 | 
            -
              | 
| 1013 | 
            -
              | 
| 1014 | 
            -
             * | 
| 1015 | 
            -
              | 
| 1016 | 
            -
              | 
| 1017 | 
            -
              | 
| 1018 | 
            -
             | 
| 1019 | 
            -
             | 
| 1020 | 
            -
             | 
| 1021 | 
            -
             | 
| 1022 | 
            -
             | 
| 1023 | 
            -
             | 
| 1024 | 
            -
             | 
| 1025 | 
            -
             * | 
| 1026 | 
            -
             *
         | 
| 1027 | 
            -
             *  | 
| 1028 | 
            -
              | 
| 1029 | 
            -
             | 
| 1030 | 
            -
             | 
| 1031 | 
            -
             | 
| 1032 | 
            -
             | 
| 1033 | 
            -
             | 
| 1034 | 
            -
             | 
| 1035 | 
            -
             | 
| 1036 | 
            -
             | 
| 1037 | 
            -
              | 
| 1038 | 
            -
              | 
| 1039 | 
            -
             | 
| 1040 | 
            -
              | 
| 1041 | 
            -
             | 
| 1042 | 
            -
              | 
| 1043 | 
            -
             | 
| 1044 | 
            -
             | 
| 1045 | 
            -
             | 
| 1046 | 
            -
             | 
| 1047 | 
            -
             | 
| 1048 | 
            -
             | 
| 1049 | 
            -
             | 
| 1050 | 
            -
                 | 
| 1051 | 
            -
                 | 
| 1052 | 
            -
             | 
| 1053 | 
            -
             | 
| 1054 | 
            -
                 | 
| 1055 | 
            -
             | 
| 1056 | 
            -
            # | 
| 1057 | 
            -
             | 
| 1058 | 
            -
             | 
| 1059 | 
            -
             | 
| 1060 | 
            -
             | 
| 1061 | 
            -
             | 
| 1062 | 
            -
             | 
| 1063 | 
            -
             | 
| 1064 | 
            -
                 | 
| 1065 | 
            -
                 | 
| 1066 | 
            -
             | 
| 1067 | 
            -
             | 
| 1068 | 
            -
                 | 
| 1069 | 
            -
             | 
| 1070 | 
            -
             | 
| 1071 | 
            -
                 | 
| 1072 | 
            -
                 | 
| 1073 | 
            -
                 | 
| 1074 | 
            -
                 | 
| 1075 | 
            -
             | 
| 1076 | 
            -
                 | 
| 1077 | 
            -
             | 
| 1078 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1079 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1080 | 
            -
             | 
| 1081 | 
            -
             | 
| 1082 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1083 | 
            -
             | 
| 1084 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1085 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1086 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1087 | 
            -
             | 
| 1088 | 
            -
                 | 
| 1089 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1090 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1091 | 
            -
             | 
| 1092 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1093 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1094 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1095 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1096 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1097 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1098 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1099 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1100 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1101 | 
            -
             | 
| 1102 | 
            -
                 | 
| 1103 | 
            -
             | 
| 1104 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1105 | 
            -
             | 
| 1106 | 
            -
             | 
| 1107 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1108 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1109 | 
            -
             | 
| 1110 | 
            -
                 | 
| 1111 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1112 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1113 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1114 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1115 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1116 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1117 | 
            -
             | 
| 1118 | 
            -
             | 
| 1119 | 
            -
                rb_define_method(cXMLWriter, " | 
| 1120 | 
            -
             | 
| 1121 | 
            -
                 | 
| 1122 | 
            -
             | 
| 1123 | 
            -
             | 
| 1124 | 
            -
             | 
| 1125 | 
            -
                rb_define_method(cXMLWriter, "write_attribute", rxml_writer_write_attribute, 2);
         | 
| 1126 | 
            -
                rb_define_method(cXMLWriter, "write_attribute_ns", rxml_writer_write_attribute_ns, -1);
         | 
| 1127 | 
            -
                rb_define_method(cXMLWriter, "write_comment", rxml_writer_write_comment, 1);
         | 
| 1128 | 
            -
                rb_define_method(cXMLWriter, "write_cdata", rxml_writer_write_cdata, 1);
         | 
| 1129 | 
            -
                rb_define_method(cXMLWriter, "write_element", rxml_writer_write_element, -1);
         | 
| 1130 | 
            -
                rb_define_method(cXMLWriter, "write_element_ns", rxml_writer_write_element_ns, -1);
         | 
| 1131 | 
            -
                rb_define_method(cXMLWriter, "write_pi", rxml_writer_write_pi, 2);
         | 
| 1132 | 
            -
             | 
| 1133 | 
            -
                rb_define_method(cXMLWriter, "result", rxml_writer_result, 0);
         | 
| 1134 | 
            -
             | 
| 1135 | 
            -
                rb_undef_method(CLASS_OF(cXMLWriter), "new");
         | 
| 1136 | 
            -
            #endif
         | 
| 1137 | 
            -
            }
         | 
| 1138 | 
            -
             | 
| 1 | 
            +
            #include "ruby_libxml.h"
         | 
| 2 | 
            +
            #include "ruby_xml_writer.h"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            #ifdef LIBXML_WRITER_ENABLED
         | 
| 5 | 
            +
            #include <libxml/xmlwriter.h>
         | 
| 6 | 
            +
            #endif
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            VALUE cXMLWriter;
         | 
| 9 | 
            +
            static VALUE sEncoding, sStandalone;
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            #ifdef LIBXML_WRITER_ENABLED
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            /*
         | 
| 14 | 
            +
             * Document-class: LibXML::XML::Writer
         | 
| 15 | 
            +
             *
         | 
| 16 | 
            +
             * The XML::Writer class provides a simpler, alternative way to build a valid
         | 
| 17 | 
            +
             * XML document from scratch (forward-only) compared to a DOM approach (based
         | 
| 18 | 
            +
             * on XML::Document class).
         | 
| 19 | 
            +
             *
         | 
| 20 | 
            +
             * For a more in depth tutorial, albeit in C, see http://xmlsoft.org/xmlwriter.html
         | 
| 21 | 
            +
             */
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            #include <libxml/xmlwriter.h>
         | 
| 24 | 
            +
             | 
| 25 | 
            +
             | 
| 26 | 
            +
            typedef enum
         | 
| 27 | 
            +
            {
         | 
| 28 | 
            +
                RXMLW_OUTPUT_NONE,
         | 
| 29 | 
            +
                RXMLW_OUTPUT_IO,
         | 
| 30 | 
            +
                RXMLW_OUTPUT_DOC,
         | 
| 31 | 
            +
                RXMLW_OUTPUT_STRING
         | 
| 32 | 
            +
            } rxmlw_output_type;
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            typedef struct
         | 
| 35 | 
            +
            {
         | 
| 36 | 
            +
                VALUE output;
         | 
| 37 | 
            +
                rb_encoding* encoding;
         | 
| 38 | 
            +
                xmlBufferPtr buffer;
         | 
| 39 | 
            +
                xmlTextWriterPtr writer;
         | 
| 40 | 
            +
                rxmlw_output_type output_type;
         | 
| 41 | 
            +
                int closed;
         | 
| 42 | 
            +
            } rxml_writer_object;
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            static void rxml_writer_free(rxml_writer_object* rwo)
         | 
| 45 | 
            +
            {
         | 
| 46 | 
            +
            #if 0 /* seems to be done by xmlFreeTextWriter */
         | 
| 47 | 
            +
                if (NULL != rwo->buffer)
         | 
| 48 | 
            +
                {
         | 
| 49 | 
            +
                    xmlBufferFree(rwo->buffer);
         | 
| 50 | 
            +
                }
         | 
| 51 | 
            +
            #endif
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                rwo->closed = 1;
         | 
| 54 | 
            +
                xmlFreeTextWriter(rwo->writer);
         | 
| 55 | 
            +
                xfree(rwo);
         | 
| 56 | 
            +
            }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            static void rxml_writer_mark(rxml_writer_object* rwo)
         | 
| 59 | 
            +
            {
         | 
| 60 | 
            +
                if (!NIL_P(rwo->output))
         | 
| 61 | 
            +
                {
         | 
| 62 | 
            +
                    rb_gc_mark(rwo->output);
         | 
| 63 | 
            +
                }
         | 
| 64 | 
            +
            }
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            static VALUE rxml_writer_wrap(rxml_writer_object* rwo)
         | 
| 67 | 
            +
            {
         | 
| 68 | 
            +
                return Data_Wrap_Struct(cXMLWriter, rxml_writer_mark, rxml_writer_free, rwo);
         | 
| 69 | 
            +
            }
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            static rxml_writer_object* rxml_textwriter_get(VALUE obj)
         | 
| 72 | 
            +
            {
         | 
| 73 | 
            +
                rxml_writer_object* rwo;
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                Data_Get_Struct(obj, rxml_writer_object, rwo);
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                return rwo;
         | 
| 78 | 
            +
            }
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            int rxml_writer_write_callback(void* context, const char* buffer, int len)
         | 
| 81 | 
            +
            {
         | 
| 82 | 
            +
                rxml_writer_object* rwo = context;
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                if (rwo->closed)
         | 
| 85 | 
            +
                {
         | 
| 86 | 
            +
                    return 0;
         | 
| 87 | 
            +
                }
         | 
| 88 | 
            +
                else
         | 
| 89 | 
            +
                {
         | 
| 90 | 
            +
                    return rxml_write_callback(rwo->output, buffer, len);
         | 
| 91 | 
            +
                }
         | 
| 92 | 
            +
            }
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            /* ===== public class methods ===== */
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            /* call-seq:
         | 
| 97 | 
            +
             *    XML::Writer::io(io) -> XML::Writer
         | 
| 98 | 
            +
             *
         | 
| 99 | 
            +
             * Creates a XML::Writer which will write XML directly into an IO object.
         | 
| 100 | 
            +
             */
         | 
| 101 | 
            +
            static VALUE rxml_writer_io(VALUE klass, VALUE io)
         | 
| 102 | 
            +
            {
         | 
| 103 | 
            +
                xmlOutputBufferPtr out;
         | 
| 104 | 
            +
                rxml_writer_object* rwo;
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                rwo = ALLOC(rxml_writer_object);
         | 
| 107 | 
            +
                rwo->output = io;
         | 
| 108 | 
            +
                rwo->buffer = NULL;
         | 
| 109 | 
            +
                rwo->closed = 0;
         | 
| 110 | 
            +
                rwo->encoding = rb_enc_get(io);
         | 
| 111 | 
            +
                if (!rwo->encoding)
         | 
| 112 | 
            +
                    rwo->encoding = rb_utf8_encoding();
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                rwo->output_type = RXMLW_OUTPUT_IO;
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name);
         | 
| 117 | 
            +
                if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr)))
         | 
| 118 | 
            +
                {
         | 
| 119 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 120 | 
            +
                }
         | 
| 121 | 
            +
                if (NULL == (rwo->writer = xmlNewTextWriter(out)))
         | 
| 122 | 
            +
                {
         | 
| 123 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 124 | 
            +
                }
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                return rxml_writer_wrap(rwo);
         | 
| 127 | 
            +
            }
         | 
| 128 | 
            +
             | 
| 129 | 
            +
             | 
| 130 | 
            +
            /* call-seq:
         | 
| 131 | 
            +
             *    XML::Writer::file(path) -> XML::Writer
         | 
| 132 | 
            +
             *
         | 
| 133 | 
            +
             * Creates a XML::Writer object which will write XML into the file with
         | 
| 134 | 
            +
             * the given name.
         | 
| 135 | 
            +
             */
         | 
| 136 | 
            +
            static VALUE rxml_writer_file(VALUE klass, VALUE filename)
         | 
| 137 | 
            +
            {
         | 
| 138 | 
            +
                rxml_writer_object* rwo;
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                rwo = ALLOC(rxml_writer_object);
         | 
| 141 | 
            +
                rwo->output = Qnil;
         | 
| 142 | 
            +
                rwo->buffer = NULL;
         | 
| 143 | 
            +
                rwo->closed = 0;
         | 
| 144 | 
            +
                rwo->encoding = rb_utf8_encoding();
         | 
| 145 | 
            +
                rwo->output_type = RXMLW_OUTPUT_NONE;
         | 
| 146 | 
            +
                if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
         | 
| 147 | 
            +
                {
         | 
| 148 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 149 | 
            +
                }
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                return rxml_writer_wrap(rwo);
         | 
| 152 | 
            +
            }
         | 
| 153 | 
            +
             | 
| 154 | 
            +
            /* call-seq:
         | 
| 155 | 
            +
             *    XML::Writer::string -> XML::Writer
         | 
| 156 | 
            +
             *
         | 
| 157 | 
            +
             * Creates a XML::Writer which will write XML into memory, as string.
         | 
| 158 | 
            +
             */
         | 
| 159 | 
            +
            static VALUE rxml_writer_string(VALUE klass)
         | 
| 160 | 
            +
            {
         | 
| 161 | 
            +
                rxml_writer_object* rwo;
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                rwo = ALLOC(rxml_writer_object);
         | 
| 164 | 
            +
                rwo->output = Qnil;
         | 
| 165 | 
            +
                rwo->closed = 0;
         | 
| 166 | 
            +
                rwo->encoding = rb_utf8_encoding();
         | 
| 167 | 
            +
                rwo->output_type = RXMLW_OUTPUT_STRING;
         | 
| 168 | 
            +
                if (NULL == (rwo->buffer = xmlBufferCreate()))
         | 
| 169 | 
            +
                {
         | 
| 170 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 171 | 
            +
                }
         | 
| 172 | 
            +
                if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
         | 
| 173 | 
            +
                {
         | 
| 174 | 
            +
                    xmlBufferFree(rwo->buffer);
         | 
| 175 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 176 | 
            +
                }
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                return rxml_writer_wrap(rwo);
         | 
| 179 | 
            +
            }
         | 
| 180 | 
            +
             | 
| 181 | 
            +
            /* call-seq:
         | 
| 182 | 
            +
             *    XML::Writer::document -> XML::Writer
         | 
| 183 | 
            +
             *
         | 
| 184 | 
            +
             * Creates a XML::Writer which will write into an in memory XML::Document
         | 
| 185 | 
            +
             */
         | 
| 186 | 
            +
            static VALUE rxml_writer_doc(VALUE klass)
         | 
| 187 | 
            +
            {
         | 
| 188 | 
            +
                xmlDocPtr doc;
         | 
| 189 | 
            +
                rxml_writer_object* rwo;
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                rwo = ALLOC(rxml_writer_object);
         | 
| 192 | 
            +
                rwo->buffer = NULL;
         | 
| 193 | 
            +
                rwo->output = Qnil;
         | 
| 194 | 
            +
                rwo->closed = 0;
         | 
| 195 | 
            +
                rwo->encoding = rb_utf8_encoding();
         | 
| 196 | 
            +
                rwo->output_type = RXMLW_OUTPUT_DOC;
         | 
| 197 | 
            +
                if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
         | 
| 198 | 
            +
                {
         | 
| 199 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 200 | 
            +
                }
         | 
| 201 | 
            +
                rwo->output = rxml_document_wrap(doc);
         | 
| 202 | 
            +
             | 
| 203 | 
            +
                return rxml_writer_wrap(rwo);
         | 
| 204 | 
            +
            }
         | 
| 205 | 
            +
             | 
| 206 | 
            +
            /* ===== public instance methods ===== */
         | 
| 207 | 
            +
             | 
| 208 | 
            +
            /* call-seq:
         | 
| 209 | 
            +
             *    writer.flush(empty? = true) -> (num|string)
         | 
| 210 | 
            +
             *
         | 
| 211 | 
            +
             * Flushes the output buffer. Returns the number of written bytes or
         | 
| 212 | 
            +
             * the current content of the internal buffer for a in memory XML::Writer.
         | 
| 213 | 
            +
             * If +empty?+ is +true+, and for a in memory XML::Writer, this internel
         | 
| 214 | 
            +
             * buffer is empty.
         | 
| 215 | 
            +
             */
         | 
| 216 | 
            +
            static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self)
         | 
| 217 | 
            +
            {
         | 
| 218 | 
            +
                int ret;
         | 
| 219 | 
            +
                VALUE empty;
         | 
| 220 | 
            +
                rxml_writer_object* rwo;
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                rb_scan_args(argc, argv, "01", &empty);
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                rwo = rxml_textwriter_get(self);
         | 
| 225 | 
            +
                if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
         | 
| 226 | 
            +
                {
         | 
| 227 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 228 | 
            +
                }
         | 
| 229 | 
            +
             | 
| 230 | 
            +
                if (NULL != rwo->buffer)
         | 
| 231 | 
            +
                {
         | 
| 232 | 
            +
                    VALUE content;
         | 
| 233 | 
            +
             | 
| 234 | 
            +
                    content = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
         | 
| 235 | 
            +
                    if (NIL_P(empty) || RTEST(empty))
         | 
| 236 | 
            +
                    { /* nil = default value = true */
         | 
| 237 | 
            +
                        xmlBufferEmpty(rwo->buffer);
         | 
| 238 | 
            +
                    }
         | 
| 239 | 
            +
             | 
| 240 | 
            +
                    return content;
         | 
| 241 | 
            +
                }
         | 
| 242 | 
            +
                else
         | 
| 243 | 
            +
                {
         | 
| 244 | 
            +
                    return INT2NUM(ret);
         | 
| 245 | 
            +
                }
         | 
| 246 | 
            +
            }
         | 
| 247 | 
            +
             | 
| 248 | 
            +
            /* call-seq:
         | 
| 249 | 
            +
             *    writer.result -> (XML::Document|"string"|nil)
         | 
| 250 | 
            +
             *
         | 
| 251 | 
            +
             * Returns the associated result object to the XML::Writer creation.
         | 
| 252 | 
            +
             * A String for a XML::Writer object created with XML::Writer::string,
         | 
| 253 | 
            +
             * a XML::Document with XML::Writer::document, etc.
         | 
| 254 | 
            +
             */
         | 
| 255 | 
            +
            static VALUE rxml_writer_result(VALUE self)
         | 
| 256 | 
            +
            {
         | 
| 257 | 
            +
                VALUE ret = Qnil;
         | 
| 258 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 259 | 
            +
                int bytesWritten = xmlTextWriterFlush(rwo->writer);
         | 
| 260 | 
            +
             | 
| 261 | 
            +
                if (bytesWritten == -1)
         | 
| 262 | 
            +
                {
         | 
| 263 | 
            +
                    rxml_raise(xmlGetLastError());
         | 
| 264 | 
            +
                }
         | 
| 265 | 
            +
             | 
| 266 | 
            +
                switch (rwo->output_type)
         | 
| 267 | 
            +
                {
         | 
| 268 | 
            +
                case RXMLW_OUTPUT_DOC:
         | 
| 269 | 
            +
                    ret = rwo->output;
         | 
| 270 | 
            +
                    break;
         | 
| 271 | 
            +
                case RXMLW_OUTPUT_STRING:
         | 
| 272 | 
            +
                    ret = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
         | 
| 273 | 
            +
                    break;
         | 
| 274 | 
            +
                case RXMLW_OUTPUT_IO:
         | 
| 275 | 
            +
                case RXMLW_OUTPUT_NONE:
         | 
| 276 | 
            +
                    break;
         | 
| 277 | 
            +
                default:
         | 
| 278 | 
            +
                    rb_bug("unexpected output");
         | 
| 279 | 
            +
                    break;
         | 
| 280 | 
            +
                }
         | 
| 281 | 
            +
             | 
| 282 | 
            +
                return ret;
         | 
| 283 | 
            +
            }
         | 
| 284 | 
            +
             | 
| 285 | 
            +
            /* ===== private helpers ===== */
         | 
| 286 | 
            +
            static void encodeStrings(rb_encoding* encoding, int count, VALUE* strings, const xmlChar** encoded_strings)
         | 
| 287 | 
            +
            {
         | 
| 288 | 
            +
                for (int i = 0; i < count; i++)
         | 
| 289 | 
            +
                {
         | 
| 290 | 
            +
                    VALUE string = strings[i];
         | 
| 291 | 
            +
             | 
| 292 | 
            +
                    if (NIL_P(string))
         | 
| 293 | 
            +
                    {
         | 
| 294 | 
            +
                        encoded_strings[i] = NULL;
         | 
| 295 | 
            +
                    }
         | 
| 296 | 
            +
                    else
         | 
| 297 | 
            +
                    {
         | 
| 298 | 
            +
                        VALUE encoded = rb_str_conv_enc(strings[i], rb_enc_get(string), encoding);
         | 
| 299 | 
            +
                        encoded_strings[i] = BAD_CAST StringValueCStr(encoded);
         | 
| 300 | 
            +
                    }
         | 
| 301 | 
            +
                }
         | 
| 302 | 
            +
            }
         | 
| 303 | 
            +
             | 
| 304 | 
            +
            static VALUE invoke_void_arg_function(VALUE self, int (*fn)(xmlTextWriterPtr))
         | 
| 305 | 
            +
            {
         | 
| 306 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 307 | 
            +
                int result = fn(rwo->writer);
         | 
| 308 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 309 | 
            +
            }
         | 
| 310 | 
            +
             | 
| 311 | 
            +
            static VALUE invoke_single_arg_function(VALUE self, int (*fn)(xmlTextWriterPtr, const xmlChar *), VALUE value)
         | 
| 312 | 
            +
            {
         | 
| 313 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 314 | 
            +
             | 
| 315 | 
            +
                VALUE rubyStrings[] = { value };
         | 
| 316 | 
            +
                const xmlChar* xmlStrings[] = { NULL };
         | 
| 317 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 318 | 
            +
             | 
| 319 | 
            +
                int result = fn(rwo->writer, xmlStrings[0]);
         | 
| 320 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 321 | 
            +
            }
         | 
| 322 | 
            +
             | 
| 323 | 
            +
             | 
| 324 | 
            +
            /* ===== public instance methods ===== */
         | 
| 325 | 
            +
             | 
| 326 | 
            +
            #if LIBXML_VERSION >= 20605
         | 
| 327 | 
            +
            /* call-seq:
         | 
| 328 | 
            +
             *    writer.set_indent(indentation) -> (true|false)
         | 
| 329 | 
            +
             *
         | 
| 330 | 
            +
             * Toggles indentation on or off. Returns +false+ on failure.
         | 
| 331 | 
            +
             *
         | 
| 332 | 
            +
             * Availability: libxml2 >= 2.6.5
         | 
| 333 | 
            +
             */
         | 
| 334 | 
            +
            static VALUE rxml_writer_set_indent(VALUE self, VALUE indentation)
         | 
| 335 | 
            +
            {
         | 
| 336 | 
            +
                int ret;
         | 
| 337 | 
            +
                rxml_writer_object* rwo;
         | 
| 338 | 
            +
             | 
| 339 | 
            +
                rwo = rxml_textwriter_get(self);
         | 
| 340 | 
            +
                ret = xmlTextWriterSetIndent(rwo->writer, RTEST(indentation));
         | 
| 341 | 
            +
             | 
| 342 | 
            +
                return (-1 == ret ? Qfalse : Qtrue);
         | 
| 343 | 
            +
            }
         | 
| 344 | 
            +
             | 
| 345 | 
            +
            /* call-seq:
         | 
| 346 | 
            +
             *    writer.set_indent_string(string) -> (true|false)
         | 
| 347 | 
            +
             *
         | 
| 348 | 
            +
             * Sets the string to use to indent each element of the document.
         | 
| 349 | 
            +
             * Don't forget to enable indentation with set_indent. Returns
         | 
| 350 | 
            +
             * +false+ on failure.
         | 
| 351 | 
            +
             *
         | 
| 352 | 
            +
             * Availability: libxml2 >= 2.6.5
         | 
| 353 | 
            +
             */
         | 
| 354 | 
            +
            static VALUE rxml_writer_set_indent_string(VALUE self, VALUE indentation)
         | 
| 355 | 
            +
            {
         | 
| 356 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterSetIndentString, indentation);
         | 
| 357 | 
            +
            }
         | 
| 358 | 
            +
            #endif /* LIBXML_VERSION >= 20605 */
         | 
| 359 | 
            +
             | 
| 360 | 
            +
            /* ===== public full tag interface ===== */
         | 
| 361 | 
            +
             | 
| 362 | 
            +
            /* write_<X> = start_<X> + write_string + end_<X> */
         | 
| 363 | 
            +
             | 
| 364 | 
            +
            /* call-seq:
         | 
| 365 | 
            +
             *    writer.write_comment(content) -> (true|false)
         | 
| 366 | 
            +
             *
         | 
| 367 | 
            +
             * Writes a full comment tag, all at once. Returns +false+ on failure.
         | 
| 368 | 
            +
             * This is equivalent to start_comment + write_string(content) + end_comment.
         | 
| 369 | 
            +
             */
         | 
| 370 | 
            +
            static VALUE rxml_writer_write_comment(VALUE self, VALUE content)
         | 
| 371 | 
            +
            {
         | 
| 372 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterWriteComment, content);
         | 
| 373 | 
            +
            }
         | 
| 374 | 
            +
             | 
| 375 | 
            +
            /* call-seq:
         | 
| 376 | 
            +
             *    writer.write_cdata(content) -> (true|false)
         | 
| 377 | 
            +
             *
         | 
| 378 | 
            +
             * Writes a full CDATA section, all at once. Returns +false+ on failure.
         | 
| 379 | 
            +
             * This is equivalent to start_cdata + write_string(content) + end_cdata.
         | 
| 380 | 
            +
             */
         | 
| 381 | 
            +
            static VALUE rxml_writer_write_cdata(VALUE self, VALUE content)
         | 
| 382 | 
            +
            {
         | 
| 383 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterWriteCDATA, content);
         | 
| 384 | 
            +
            }
         | 
| 385 | 
            +
             | 
| 386 | 
            +
            static VALUE rxml_writer_start_element(VALUE, VALUE);
         | 
| 387 | 
            +
            static VALUE rxml_writer_start_element_ns(int, VALUE*, VALUE);
         | 
| 388 | 
            +
            static VALUE rxml_writer_end_element(VALUE);
         | 
| 389 | 
            +
             | 
| 390 | 
            +
            /* call-seq:
         | 
| 391 | 
            +
             *    writer.write_element(name, content) -> (true|false)
         | 
| 392 | 
            +
             *
         | 
| 393 | 
            +
             * Writes a full element tag, all at once. Returns +false+ on failure.
         | 
| 394 | 
            +
             * This is equivalent to start_element(name) + write_string(content) +
         | 
| 395 | 
            +
             * end_element.
         | 
| 396 | 
            +
             */
         | 
| 397 | 
            +
            static VALUE rxml_writer_write_element(int argc, VALUE* argv, VALUE self)
         | 
| 398 | 
            +
            {
         | 
| 399 | 
            +
                VALUE name, content;
         | 
| 400 | 
            +
             | 
| 401 | 
            +
                rb_scan_args(argc, argv, "11", &name, &content);
         | 
| 402 | 
            +
                if (Qnil == content)
         | 
| 403 | 
            +
                {
         | 
| 404 | 
            +
                    if (Qfalse == rxml_writer_start_element(self, name))
         | 
| 405 | 
            +
                    {
         | 
| 406 | 
            +
                        return Qfalse;
         | 
| 407 | 
            +
                    }
         | 
| 408 | 
            +
                    return rxml_writer_end_element(self);
         | 
| 409 | 
            +
                }
         | 
| 410 | 
            +
                else
         | 
| 411 | 
            +
                {
         | 
| 412 | 
            +
                    rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 413 | 
            +
                    VALUE rubyStrings[] =  {name, content};
         | 
| 414 | 
            +
                    const xmlChar* xmlStrings[] =  {NULL, NULL};
         | 
| 415 | 
            +
                    encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 416 | 
            +
             | 
| 417 | 
            +
                    int result = xmlTextWriterWriteElement(rwo->writer, xmlStrings[0], xmlStrings[1]);
         | 
| 418 | 
            +
                    return (result == -1 ? Qfalse : Qtrue);
         | 
| 419 | 
            +
                }
         | 
| 420 | 
            +
            }
         | 
| 421 | 
            +
             | 
| 422 | 
            +
            #define ARRAY_SIZE(array) \
         | 
| 423 | 
            +
                (sizeof(array) / sizeof((array)[0]))
         | 
| 424 | 
            +
             | 
| 425 | 
            +
            /* call-seq:
         | 
| 426 | 
            +
             *    writer.write_element_ns(prefix, name, namespaceURI, content) -> (true|false)
         | 
| 427 | 
            +
             *
         | 
| 428 | 
            +
             * Writes a full namespaced element tag, all at once. Returns +false+ on failure.
         | 
| 429 | 
            +
             * This is a shortcut for start_element_ns(prefix, name, namespaceURI) +
         | 
| 430 | 
            +
             * write_string(content) + end_element.
         | 
| 431 | 
            +
             *
         | 
| 432 | 
            +
             * Notes:
         | 
| 433 | 
            +
             * - by default, the xmlns: definition is repeated on every element. If you want
         | 
| 434 | 
            +
             * the prefix, but don't want the xmlns: declaration repeated, set +namespaceURI+
         | 
| 435 | 
            +
             * to nil or omit it. Don't forget to declare the namespace prefix somewhere
         | 
| 436 | 
            +
             * earlier.
         | 
| 437 | 
            +
             * - +content+ can be omitted for an empty tag
         | 
| 438 | 
            +
             */
         | 
| 439 | 
            +
            static VALUE rxml_writer_write_element_ns(int argc, VALUE* argv, VALUE self)
         | 
| 440 | 
            +
            {
         | 
| 441 | 
            +
                VALUE prefix, name, namespaceURI, content;
         | 
| 442 | 
            +
             | 
| 443 | 
            +
                rb_scan_args(argc, argv, "22", &prefix, &name, &namespaceURI, &content);
         | 
| 444 | 
            +
                if (Qnil == content)
         | 
| 445 | 
            +
                {
         | 
| 446 | 
            +
                    VALUE argv[3] = { prefix, name, namespaceURI };
         | 
| 447 | 
            +
             | 
| 448 | 
            +
                    if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self))
         | 
| 449 | 
            +
                    {
         | 
| 450 | 
            +
                        return Qfalse;
         | 
| 451 | 
            +
                    }
         | 
| 452 | 
            +
                    return rxml_writer_end_element(self);
         | 
| 453 | 
            +
                }
         | 
| 454 | 
            +
                else
         | 
| 455 | 
            +
                {
         | 
| 456 | 
            +
                    rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 457 | 
            +
                    VALUE rubyStrings[] =  {prefix, name, namespaceURI, content};
         | 
| 458 | 
            +
                    const xmlChar* xmlStrings[] =  {NULL, NULL, NULL, NULL};
         | 
| 459 | 
            +
                    encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 460 | 
            +
                    int result = xmlTextWriterWriteElementNS(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2], xmlStrings[3]);
         | 
| 461 | 
            +
                    return (result == -1 ? Qfalse : Qtrue);
         | 
| 462 | 
            +
                }
         | 
| 463 | 
            +
            }
         | 
| 464 | 
            +
             | 
| 465 | 
            +
            /* call-seq:
         | 
| 466 | 
            +
             *    writer.write_attribute(name, content) -> (true|false)
         | 
| 467 | 
            +
             *
         | 
| 468 | 
            +
             * Writes a full attribute, all at once. Returns +false+ on failure.
         | 
| 469 | 
            +
             * Same as start_attribute(name) + write_string(content) + end_attribute.
         | 
| 470 | 
            +
             */
         | 
| 471 | 
            +
            static VALUE rxml_writer_write_attribute(VALUE self, VALUE name, VALUE content)
         | 
| 472 | 
            +
            {
         | 
| 473 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 474 | 
            +
                VALUE rubyStrings[] =  {name, content};
         | 
| 475 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL};
         | 
| 476 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 477 | 
            +
                int result = xmlTextWriterWriteAttribute(rwo->writer, xmlStrings[0], xmlStrings[1]);
         | 
| 478 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 479 | 
            +
            }
         | 
| 480 | 
            +
             | 
| 481 | 
            +
            /* call-seq:
         | 
| 482 | 
            +
             *    writer.write_attribute_ns(prefix, name, namespaceURI, content) -> (true|false)
         | 
| 483 | 
            +
             *
         | 
| 484 | 
            +
             * Writes a full namespaced attribute, all at once. Returns +false+ on failure.
         | 
| 485 | 
            +
             * Same as start_attribute_ns(prefix, name, namespaceURI) +
         | 
| 486 | 
            +
             * write_string(content) + end_attribute.
         | 
| 487 | 
            +
             *
         | 
| 488 | 
            +
             * Notes:
         | 
| 489 | 
            +
             * - by default, the xmlns: definition is repeated on every element. If you want
         | 
| 490 | 
            +
             * the prefix, but don't want the xmlns: declaration repeated, set +namespaceURI+
         | 
| 491 | 
            +
             * to nil or omit it. Don't forget to declare the namespace prefix somewhere
         | 
| 492 | 
            +
             * earlier.
         | 
| 493 | 
            +
             * - +content+ can be omitted too for an empty attribute
         | 
| 494 | 
            +
             */
         | 
| 495 | 
            +
            static VALUE rxml_writer_write_attribute_ns(int argc, VALUE* argv, VALUE self)
         | 
| 496 | 
            +
            {
         | 
| 497 | 
            +
                VALUE prefix, name, namespaceURI, content;
         | 
| 498 | 
            +
                rb_scan_args(argc, argv, "22", &prefix, &name, &namespaceURI, &content);
         | 
| 499 | 
            +
             | 
| 500 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 501 | 
            +
                VALUE rubyStrings[] =  {prefix, name, namespaceURI, content};
         | 
| 502 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL, NULL};
         | 
| 503 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 504 | 
            +
                int result = xmlTextWriterWriteAttributeNS(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2], xmlStrings[3]);
         | 
| 505 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 506 | 
            +
            }
         | 
| 507 | 
            +
             | 
| 508 | 
            +
            /* call-seq:
         | 
| 509 | 
            +
             *    writer.write_pi(target, content) -> (true|false)
         | 
| 510 | 
            +
             *
         | 
| 511 | 
            +
             * Writes a full CDATA tag, all at once. Returns +false+ on failure.
         | 
| 512 | 
            +
             * This is a shortcut for start_pi(target) + write_string(content) + end_pi.
         | 
| 513 | 
            +
             */
         | 
| 514 | 
            +
            static VALUE rxml_writer_write_pi(VALUE self, VALUE target, VALUE content)
         | 
| 515 | 
            +
            {
         | 
| 516 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 517 | 
            +
                VALUE rubyStrings[] =  {target, content};
         | 
| 518 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL};
         | 
| 519 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 520 | 
            +
                int result = xmlTextWriterWritePI(rwo->writer, xmlStrings[0], xmlStrings[1]);
         | 
| 521 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 522 | 
            +
            }
         | 
| 523 | 
            +
             | 
| 524 | 
            +
            /* ===== public start/end interface ===== */
         | 
| 525 | 
            +
             | 
| 526 | 
            +
            /* call-seq:
         | 
| 527 | 
            +
             *    writer.write_string(content) -> (true|false)
         | 
| 528 | 
            +
             *
         | 
| 529 | 
            +
             * Safely (problematic characters are internally translated to their
         | 
| 530 | 
            +
             * associated named entities) writes a string into the current node
         | 
| 531 | 
            +
             * (attribute, element, comment, ...). Returns +false+ on failure.
         | 
| 532 | 
            +
             */
         | 
| 533 | 
            +
            static VALUE rxml_writer_write_string(VALUE self, VALUE content)
         | 
| 534 | 
            +
            {
         | 
| 535 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterWriteString, content);
         | 
| 536 | 
            +
            }
         | 
| 537 | 
            +
             | 
| 538 | 
            +
            /* call-seq:
         | 
| 539 | 
            +
             *    writer.write_raw(content) -> (true|false)
         | 
| 540 | 
            +
             *
         | 
| 541 | 
            +
             * Writes the string +content+ as is, reserved characters are not
         | 
| 542 | 
            +
             * translated to their associated entities. Returns +false+ on failure.
         | 
| 543 | 
            +
             * Consider write_string to handle them.
         | 
| 544 | 
            +
             */
         | 
| 545 | 
            +
            static VALUE rxml_writer_write_raw(VALUE self, VALUE content)
         | 
| 546 | 
            +
            {
         | 
| 547 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterWriteRaw, content);
         | 
| 548 | 
            +
            }
         | 
| 549 | 
            +
             | 
| 550 | 
            +
            /* call-seq:
         | 
| 551 | 
            +
             *    writer.start_attribute(name) -> (true|false)
         | 
| 552 | 
            +
             *
         | 
| 553 | 
            +
             * Starts an attribute. Returns +false+ on failure.
         | 
| 554 | 
            +
             */
         | 
| 555 | 
            +
            static VALUE rxml_writer_start_attribute(VALUE self, VALUE name)
         | 
| 556 | 
            +
            {
         | 
| 557 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterStartAttribute, name);
         | 
| 558 | 
            +
            }
         | 
| 559 | 
            +
             | 
| 560 | 
            +
            /* call-seq:
         | 
| 561 | 
            +
             *    writer.start_attribute_ns(prefix, name, namespaceURI) -> (true|false)
         | 
| 562 | 
            +
             *
         | 
| 563 | 
            +
             * Starts a namespaced attribute. Returns +false+ on failure.
         | 
| 564 | 
            +
             *
         | 
| 565 | 
            +
             * Note: by default, the xmlns: definition is repeated on every element. If
         | 
| 566 | 
            +
             * you want the prefix, but don't want the xmlns: declaration repeated, set
         | 
| 567 | 
            +
             * +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
         | 
| 568 | 
            +
             * prefix somewhere earlier.
         | 
| 569 | 
            +
             */
         | 
| 570 | 
            +
            static VALUE rxml_writer_start_attribute_ns(int argc, VALUE* argv, VALUE self)
         | 
| 571 | 
            +
            {
         | 
| 572 | 
            +
                VALUE prefix, name, namespaceURI;
         | 
| 573 | 
            +
                rb_scan_args(argc, argv, "21", &prefix, &name, &namespaceURI);
         | 
| 574 | 
            +
             | 
| 575 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 576 | 
            +
                VALUE rubyStrings[] =  {prefix, name, namespaceURI};
         | 
| 577 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL};
         | 
| 578 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 579 | 
            +
                int result = xmlTextWriterStartAttributeNS(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2]);
         | 
| 580 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 581 | 
            +
            }
         | 
| 582 | 
            +
             | 
| 583 | 
            +
            /* call-seq:
         | 
| 584 | 
            +
             *    writer.end_attribute -> (true|false)
         | 
| 585 | 
            +
             *
         | 
| 586 | 
            +
             * Ends an attribute, namespaced or not. Returns +false+ on failure.
         | 
| 587 | 
            +
             */
         | 
| 588 | 
            +
            static VALUE rxml_writer_end_attribute(VALUE self)
         | 
| 589 | 
            +
            {
         | 
| 590 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndAttribute);
         | 
| 591 | 
            +
            }
         | 
| 592 | 
            +
             | 
| 593 | 
            +
            #if LIBXML_VERSION >= 20607
         | 
| 594 | 
            +
            /* call-seq:
         | 
| 595 | 
            +
             *    writer.start_comment -> (true|false)
         | 
| 596 | 
            +
             *
         | 
| 597 | 
            +
             * Starts a comment. Returns +false+ on failure.
         | 
| 598 | 
            +
             * Note: libxml2 >= 2.6.7 required
         | 
| 599 | 
            +
             */
         | 
| 600 | 
            +
            static VALUE rxml_writer_start_comment(VALUE self)
         | 
| 601 | 
            +
            {
         | 
| 602 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterStartComment);
         | 
| 603 | 
            +
            }
         | 
| 604 | 
            +
             | 
| 605 | 
            +
            /* call-seq:
         | 
| 606 | 
            +
             *    writer.end_comment -> (true|false)
         | 
| 607 | 
            +
             *
         | 
| 608 | 
            +
             * Ends current comment, returns +false+ on failure.
         | 
| 609 | 
            +
             * Note: libxml2 >= 2.6.7 required
         | 
| 610 | 
            +
             */
         | 
| 611 | 
            +
            static VALUE rxml_writer_end_comment(VALUE self)
         | 
| 612 | 
            +
            {
         | 
| 613 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndComment);
         | 
| 614 | 
            +
            }
         | 
| 615 | 
            +
            #endif /* LIBXML_VERSION >= 20607 */
         | 
| 616 | 
            +
             | 
| 617 | 
            +
            /* call-seq:
         | 
| 618 | 
            +
             *    writer.start_element(name) -> (true|false)
         | 
| 619 | 
            +
             *
         | 
| 620 | 
            +
             * Starts a new element. Returns +false+ on failure.
         | 
| 621 | 
            +
             */
         | 
| 622 | 
            +
            static VALUE rxml_writer_start_element(VALUE self, VALUE name)
         | 
| 623 | 
            +
            {
         | 
| 624 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterStartElement, name);
         | 
| 625 | 
            +
            }
         | 
| 626 | 
            +
             | 
| 627 | 
            +
            /* call-seq:
         | 
| 628 | 
            +
             *    writer.start_element_ns(prefix, name, namespaceURI) -> (true|false)
         | 
| 629 | 
            +
             *
         | 
| 630 | 
            +
             * Starts a new namespaced element. Returns +false+ on failure.
         | 
| 631 | 
            +
             *
         | 
| 632 | 
            +
             * Note: by default, the xmlns: definition is repeated on every element. If
         | 
| 633 | 
            +
             * you want the prefix, but don't want the xmlns: declaration repeated, set
         | 
| 634 | 
            +
             * +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
         | 
| 635 | 
            +
             * prefix somewhere earlier.
         | 
| 636 | 
            +
             */
         | 
| 637 | 
            +
            static VALUE rxml_writer_start_element_ns(int argc, VALUE* argv, VALUE self)
         | 
| 638 | 
            +
            {
         | 
| 639 | 
            +
                VALUE prefix, name, namespaceURI;
         | 
| 640 | 
            +
                rb_scan_args(argc, argv, "21", &prefix, &name, &namespaceURI);
         | 
| 641 | 
            +
             | 
| 642 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 643 | 
            +
                VALUE rubyStrings[] =  {prefix, name, namespaceURI};
         | 
| 644 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL};
         | 
| 645 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 646 | 
            +
                int result = xmlTextWriterStartElementNS(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2]);
         | 
| 647 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 648 | 
            +
            }
         | 
| 649 | 
            +
             | 
| 650 | 
            +
            /* call-seq:
         | 
| 651 | 
            +
             *    writer.end_element -> (true|false)
         | 
| 652 | 
            +
             *
         | 
| 653 | 
            +
             * Ends current element, namespaced or not. Returns +false+ on failure.
         | 
| 654 | 
            +
             */
         | 
| 655 | 
            +
            static VALUE rxml_writer_end_element(VALUE self)
         | 
| 656 | 
            +
            {
         | 
| 657 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndElement);
         | 
| 658 | 
            +
            }
         | 
| 659 | 
            +
             | 
| 660 | 
            +
            /* call-seq:
         | 
| 661 | 
            +
             *    writer.write_full_end_element -> (true|false)
         | 
| 662 | 
            +
             *
         | 
| 663 | 
            +
             * Ends current element, namespaced or not. Returns +false+ on failure.
         | 
| 664 | 
            +
             * This method writes an end tag even if the element is empty (<foo></foo>),
         | 
| 665 | 
            +
             * end_element does not (<foo/>).
         | 
| 666 | 
            +
             */
         | 
| 667 | 
            +
            static VALUE rxml_writer_full_end_element(VALUE self)
         | 
| 668 | 
            +
            {
         | 
| 669 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterFullEndElement);
         | 
| 670 | 
            +
            }
         | 
| 671 | 
            +
             | 
| 672 | 
            +
            /* call-seq:
         | 
| 673 | 
            +
             *    writer.start_cdata -> (true|false)
         | 
| 674 | 
            +
             *
         | 
| 675 | 
            +
             * Starts a new CDATA section. Returns +false+ on failure.
         | 
| 676 | 
            +
             */
         | 
| 677 | 
            +
            static VALUE rxml_writer_start_cdata(VALUE self)
         | 
| 678 | 
            +
            {
         | 
| 679 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterStartCDATA);
         | 
| 680 | 
            +
            }
         | 
| 681 | 
            +
             | 
| 682 | 
            +
            /* call-seq:
         | 
| 683 | 
            +
             *    writer.end_cdata -> (true|false)
         | 
| 684 | 
            +
             *
         | 
| 685 | 
            +
             * Ends current CDATA section. Returns +false+ on failure.
         | 
| 686 | 
            +
             */
         | 
| 687 | 
            +
            static VALUE rxml_writer_end_cdata(VALUE self)
         | 
| 688 | 
            +
            {
         | 
| 689 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndCDATA);
         | 
| 690 | 
            +
            }
         | 
| 691 | 
            +
             | 
| 692 | 
            +
            /* call-seq:
         | 
| 693 | 
            +
             *    writer.start_document -> (true|false)
         | 
| 694 | 
            +
             *    writer.start_document(:encoding => XML::Encoding::UTF_8,
         | 
| 695 | 
            +
             *    :standalone => true) -> (true|false)
         | 
| 696 | 
            +
             *
         | 
| 697 | 
            +
             * Starts a new document. Returns +false+ on failure.
         | 
| 698 | 
            +
             *
         | 
| 699 | 
            +
             * You may provide an optional hash table to control XML header that will be
         | 
| 700 | 
            +
             * generated. Valid options are:
         | 
| 701 | 
            +
             * - encoding: the output document encoding, defaults to nil (= UTF-8). Valid
         | 
| 702 | 
            +
             * values are the encoding constants defined on XML::Encoding
         | 
| 703 | 
            +
             * - standalone: nil (default) or a boolean to indicate if the document is
         | 
| 704 | 
            +
             * standalone or not
         | 
| 705 | 
            +
             */
         | 
| 706 | 
            +
            static VALUE rxml_writer_start_document(int argc, VALUE* argv, VALUE self)
         | 
| 707 | 
            +
            {
         | 
| 708 | 
            +
                int ret;
         | 
| 709 | 
            +
                VALUE options = Qnil;
         | 
| 710 | 
            +
                rxml_writer_object* rwo;
         | 
| 711 | 
            +
                const xmlChar* xencoding = NULL;
         | 
| 712 | 
            +
                const char* xstandalone = NULL;
         | 
| 713 | 
            +
             | 
| 714 | 
            +
                rb_scan_args(argc, argv, "01", &options);
         | 
| 715 | 
            +
                if (!NIL_P(options))
         | 
| 716 | 
            +
                {
         | 
| 717 | 
            +
                    VALUE encoding, standalone;
         | 
| 718 | 
            +
             | 
| 719 | 
            +
                    encoding = standalone = Qnil;
         | 
| 720 | 
            +
                    Check_Type(options, T_HASH);
         | 
| 721 | 
            +
                    encoding = rb_hash_aref(options, sEncoding);
         | 
| 722 | 
            +
                    xencoding = NIL_P(encoding) ? NULL : (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding));
         | 
| 723 | 
            +
                    standalone = rb_hash_aref(options, sStandalone);
         | 
| 724 | 
            +
                    if (NIL_P(standalone))
         | 
| 725 | 
            +
                    {
         | 
| 726 | 
            +
                        xstandalone = NULL;
         | 
| 727 | 
            +
                    }
         | 
| 728 | 
            +
                    else
         | 
| 729 | 
            +
                    {
         | 
| 730 | 
            +
                        xstandalone = RTEST(standalone) ? "yes" : "no";
         | 
| 731 | 
            +
                    }
         | 
| 732 | 
            +
                }
         | 
| 733 | 
            +
                rwo = rxml_textwriter_get(self);
         | 
| 734 | 
            +
                rwo->encoding = rxml_figure_encoding(xencoding);
         | 
| 735 | 
            +
                ret = xmlTextWriterStartDocument(rwo->writer, NULL, (const char*)xencoding, xstandalone);
         | 
| 736 | 
            +
             | 
| 737 | 
            +
                return (-1 == ret ? Qfalse : Qtrue);
         | 
| 738 | 
            +
            }
         | 
| 739 | 
            +
             | 
| 740 | 
            +
            /* call-seq:
         | 
| 741 | 
            +
             *    writer.end_document -> (true|false)
         | 
| 742 | 
            +
             *
         | 
| 743 | 
            +
             * Ends current document. Returns +false+ on failure.
         | 
| 744 | 
            +
             */
         | 
| 745 | 
            +
            static VALUE rxml_writer_end_document(VALUE self)
         | 
| 746 | 
            +
            {
         | 
| 747 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndDocument);
         | 
| 748 | 
            +
            }
         | 
| 749 | 
            +
             | 
| 750 | 
            +
            /* call-seq:
         | 
| 751 | 
            +
             *    writer.start_pi(target) -> (true|false)
         | 
| 752 | 
            +
             *
         | 
| 753 | 
            +
             * Starts a new processing instruction. Returns +false+ on failure.
         | 
| 754 | 
            +
             */
         | 
| 755 | 
            +
            static VALUE rxml_writer_start_pi(VALUE self, VALUE target)
         | 
| 756 | 
            +
            {
         | 
| 757 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterStartPI, target);
         | 
| 758 | 
            +
            }
         | 
| 759 | 
            +
             | 
| 760 | 
            +
            /* call-seq:
         | 
| 761 | 
            +
             *    writer.end_pi -> (true|false)
         | 
| 762 | 
            +
             *
         | 
| 763 | 
            +
             * Ends current processing instruction. Returns +false+ on failure.
         | 
| 764 | 
            +
             */
         | 
| 765 | 
            +
            static VALUE rxml_writer_end_pi(VALUE self)
         | 
| 766 | 
            +
            {
         | 
| 767 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndPI);
         | 
| 768 | 
            +
            }
         | 
| 769 | 
            +
             | 
| 770 | 
            +
            /* call-seq:
         | 
| 771 | 
            +
             *    writer.start_dtd(qualifiedName, publicId, systemId) -> (true|false)
         | 
| 772 | 
            +
             *
         | 
| 773 | 
            +
             * Starts a DTD. Returns +false+ on failure.
         | 
| 774 | 
            +
             */
         | 
| 775 | 
            +
            static VALUE rxml_writer_start_dtd(int argc, VALUE* argv, VALUE self)
         | 
| 776 | 
            +
            {
         | 
| 777 | 
            +
                VALUE name, pubid, sysid;
         | 
| 778 | 
            +
                rb_scan_args(argc, argv, "12", &name, &pubid, &sysid);
         | 
| 779 | 
            +
             | 
| 780 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 781 | 
            +
                VALUE rubyStrings[] =  {name, pubid, sysid};
         | 
| 782 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL};
         | 
| 783 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 784 | 
            +
                int result = xmlTextWriterStartDTD(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2]);
         | 
| 785 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 786 | 
            +
            }
         | 
| 787 | 
            +
             | 
| 788 | 
            +
            /* call-seq:
         | 
| 789 | 
            +
             *    writer.start_dtd_element(qualifiedName) -> (true|false)
         | 
| 790 | 
            +
             *
         | 
| 791 | 
            +
             * Starts a DTD element (<!ELEMENT ... >). Returns +false+ on failure.
         | 
| 792 | 
            +
             */
         | 
| 793 | 
            +
            static VALUE rxml_writer_start_dtd_element(VALUE self, VALUE name)
         | 
| 794 | 
            +
            {
         | 
| 795 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterStartDTDElement, name);
         | 
| 796 | 
            +
            }
         | 
| 797 | 
            +
             | 
| 798 | 
            +
            /* call-seq:
         | 
| 799 | 
            +
             *    writer.start_dtd_entity(name, pe = false) -> (true|false)
         | 
| 800 | 
            +
             *
         | 
| 801 | 
            +
             * Starts a DTD entity (<!ENTITY ... >). Returns +false+ on failure.
         | 
| 802 | 
            +
             */
         | 
| 803 | 
            +
            static VALUE rxml_writer_start_dtd_entity(int argc, VALUE* argv, VALUE self)
         | 
| 804 | 
            +
            {
         | 
| 805 | 
            +
                VALUE name, pe;
         | 
| 806 | 
            +
                rb_scan_args(argc, argv, "11", &name, &pe);
         | 
| 807 | 
            +
             | 
| 808 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 809 | 
            +
                VALUE rubyStrings[] =  {name};
         | 
| 810 | 
            +
                const xmlChar* xmlStrings[] =  {NULL};
         | 
| 811 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 812 | 
            +
                int result = xmlTextWriterStartDTDEntity(rwo->writer, RB_TEST(pe), xmlStrings[0]);
         | 
| 813 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 814 | 
            +
            }
         | 
| 815 | 
            +
             | 
| 816 | 
            +
            /* call-seq:
         | 
| 817 | 
            +
             *    writer.start_dtd_attlist(name) -> (true|false)
         | 
| 818 | 
            +
             *
         | 
| 819 | 
            +
             * Starts a DTD attribute list (<!ATTLIST ... >). Returns +false+ on failure.
         | 
| 820 | 
            +
             */
         | 
| 821 | 
            +
            static VALUE rxml_writer_start_dtd_attlist(VALUE self, VALUE name)
         | 
| 822 | 
            +
            {
         | 
| 823 | 
            +
                return invoke_single_arg_function(self, xmlTextWriterStartDTDAttlist, name);
         | 
| 824 | 
            +
            }
         | 
| 825 | 
            +
             | 
| 826 | 
            +
            /* call-seq:
         | 
| 827 | 
            +
             *    writer.end_dtd -> (true|false)
         | 
| 828 | 
            +
             *
         | 
| 829 | 
            +
             * Ends current DTD, returns +false+ on failure.
         | 
| 830 | 
            +
             */
         | 
| 831 | 
            +
            static VALUE rxml_writer_end_dtd(VALUE self)
         | 
| 832 | 
            +
            {
         | 
| 833 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndDTD);
         | 
| 834 | 
            +
            }
         | 
| 835 | 
            +
             | 
| 836 | 
            +
            /* call-seq:
         | 
| 837 | 
            +
             *    writer.end_dtd_entity -> (true|false)
         | 
| 838 | 
            +
             *
         | 
| 839 | 
            +
             * Ends current DTD entity, returns +false+ on failure.
         | 
| 840 | 
            +
             */
         | 
| 841 | 
            +
            static VALUE rxml_writer_end_dtd_entity(VALUE self)
         | 
| 842 | 
            +
            {
         | 
| 843 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndDTDEntity);
         | 
| 844 | 
            +
            }
         | 
| 845 | 
            +
             | 
| 846 | 
            +
            /* call-seq:
         | 
| 847 | 
            +
             *    writer.end_dtd_attlist -> (true|false)
         | 
| 848 | 
            +
             *
         | 
| 849 | 
            +
             * Ends current DTD attribute list, returns +false+ on failure.
         | 
| 850 | 
            +
             */
         | 
| 851 | 
            +
            static VALUE rxml_writer_end_dtd_attlist(VALUE self)
         | 
| 852 | 
            +
            {
         | 
| 853 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndDTDAttlist);
         | 
| 854 | 
            +
            }
         | 
| 855 | 
            +
             | 
| 856 | 
            +
            /* call-seq:
         | 
| 857 | 
            +
             *    writer.end_dtd_element -> (true|false)
         | 
| 858 | 
            +
             *
         | 
| 859 | 
            +
             * Ends current DTD element, returns +false+ on failure.
         | 
| 860 | 
            +
             */
         | 
| 861 | 
            +
            static VALUE rxml_writer_end_dtd_element(VALUE self)
         | 
| 862 | 
            +
            {
         | 
| 863 | 
            +
                return invoke_void_arg_function(self, xmlTextWriterEndDTDElement);
         | 
| 864 | 
            +
            }
         | 
| 865 | 
            +
             | 
| 866 | 
            +
            /* call-seq:
         | 
| 867 | 
            +
             *    writer.write_dtd(name [ [ [, publicId ], systemId ], subset ]) -> (true|false)
         | 
| 868 | 
            +
             *
         | 
| 869 | 
            +
             * Writes a DTD, all at once. Returns +false+ on failure.
         | 
| 870 | 
            +
             * - name: dtd name
         | 
| 871 | 
            +
             * - publicId: external subset public identifier, use nil for a SYSTEM doctype
         | 
| 872 | 
            +
             * - systemId: external subset system identifier
         | 
| 873 | 
            +
             * - subset: content
         | 
| 874 | 
            +
             *
         | 
| 875 | 
            +
             * Examples:
         | 
| 876 | 
            +
             *   writer.write_dtd 'html'
         | 
| 877 | 
            +
             *     #=> <!DOCTYPE html>
         | 
| 878 | 
            +
             *   writer.write_dtd 'docbook', nil, 'http://www.docbook.org/xml/5.0/dtd/docbook.dtd'
         | 
| 879 | 
            +
             *     #=> <!DOCTYPE docbook SYSTEM "http://www.docbook.org/xml/5.0/dtd/docbook.dtd">
         | 
| 880 | 
            +
             *   writer.write_dtd 'html', '-//W3C//DTD XHTML 1.1//EN', 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'
         | 
| 881 | 
            +
             *     #=> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
         | 
| 882 | 
            +
             *   writer.write_dtd 'person', nil, nil, '<!ELEMENT person (firstname,lastname)><!ELEMENT firstname (#PCDATA)><!ELEMENT lastname (#PCDATA)>'
         | 
| 883 | 
            +
             *     #=> <!DOCTYPE person [<!ELEMENT person (firstname,lastname)><!ELEMENT firstname (#PCDATA)><!ELEMENT lastname (#PCDATA)>]>
         | 
| 884 | 
            +
             */
         | 
| 885 | 
            +
            static VALUE rxml_writer_write_dtd(int argc, VALUE* argv, VALUE self)
         | 
| 886 | 
            +
            {
         | 
| 887 | 
            +
                VALUE name, pubid, sysid, subset;
         | 
| 888 | 
            +
                rb_scan_args(argc, argv, "13", &name, &pubid, &sysid, &subset);
         | 
| 889 | 
            +
             | 
| 890 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 891 | 
            +
                VALUE rubyStrings[] =  {name, pubid, sysid, subset};
         | 
| 892 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL, NULL};
         | 
| 893 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 894 | 
            +
                int result = xmlTextWriterWriteDTD(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2], xmlStrings[3]);
         | 
| 895 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 896 | 
            +
            }
         | 
| 897 | 
            +
             | 
| 898 | 
            +
            /* call-seq:
         | 
| 899 | 
            +
             *    writer.write_dtd_attlist(name, content) -> (true|false)
         | 
| 900 | 
            +
             *
         | 
| 901 | 
            +
             * Writes a DTD attribute list, all at once. Returns +false+ on failure.
         | 
| 902 | 
            +
             *   writer.write_dtd_attlist 'id', 'ID #IMPLIED'
         | 
| 903 | 
            +
             *     #=> <!ATTLIST id ID #IMPLIED>
         | 
| 904 | 
            +
             */
         | 
| 905 | 
            +
            static VALUE rxml_writer_write_dtd_attlist(VALUE self, VALUE name, VALUE content)
         | 
| 906 | 
            +
            {
         | 
| 907 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 908 | 
            +
                VALUE rubyStrings[] =  {name, content};
         | 
| 909 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL};
         | 
| 910 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 911 | 
            +
                int result = xmlTextWriterWriteDTDAttlist(rwo->writer, xmlStrings[0], xmlStrings[1]);
         | 
| 912 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 913 | 
            +
            }
         | 
| 914 | 
            +
             | 
| 915 | 
            +
            /* call-seq:
         | 
| 916 | 
            +
             *    writer.write_dtd_element(name, content) -> (true|false)
         | 
| 917 | 
            +
             *
         | 
| 918 | 
            +
             * Writes a full DTD element, all at once. Returns +false+ on failure.
         | 
| 919 | 
            +
             *   writer.write_dtd_element 'person', '(firstname,lastname)'
         | 
| 920 | 
            +
             *     #=> <!ELEMENT person (firstname,lastname)>
         | 
| 921 | 
            +
             */
         | 
| 922 | 
            +
            static VALUE rxml_writer_write_dtd_element(VALUE self, VALUE name, VALUE content)
         | 
| 923 | 
            +
            {
         | 
| 924 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 925 | 
            +
                VALUE rubyStrings[] =  {name, content};
         | 
| 926 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL};
         | 
| 927 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 928 | 
            +
                int result = xmlTextWriterWriteDTDElement(rwo->writer, xmlStrings[0], xmlStrings[1]);
         | 
| 929 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 930 | 
            +
            }
         | 
| 931 | 
            +
             | 
| 932 | 
            +
            /* call-seq:
         | 
| 933 | 
            +
             *    writer.write_dtd_entity(name, publicId, systemId, ndataid, content, pe) -> (true|false)
         | 
| 934 | 
            +
             *
         | 
| 935 | 
            +
             * Writes a DTD entity, all at once. Returns +false+ on failure.
         | 
| 936 | 
            +
             */
         | 
| 937 | 
            +
            static VALUE rxml_writer_write_dtd_entity(VALUE self, VALUE name, VALUE pubid, VALUE sysid, VALUE ndataid, VALUE content, VALUE pe)
         | 
| 938 | 
            +
            {
         | 
| 939 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 940 | 
            +
                VALUE rubyStrings[] =  {name, pubid, sysid, ndataid, content};
         | 
| 941 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL, NULL, NULL};
         | 
| 942 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 943 | 
            +
                int result = xmlTextWriterWriteDTDEntity(rwo->writer, RB_TEST(pe), xmlStrings[0], xmlStrings[1], xmlStrings[2], xmlStrings[3], xmlStrings[4]);
         | 
| 944 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 945 | 
            +
            }
         | 
| 946 | 
            +
             | 
| 947 | 
            +
            /* call-seq:
         | 
| 948 | 
            +
             *    writer.write_dtd_external_entity(name, publicId, systemId, ndataid, pe) -> (true|false)
         | 
| 949 | 
            +
             *
         | 
| 950 | 
            +
             * Writes a DTD external entity. The entity must have been started
         | 
| 951 | 
            +
             * with start_dtd_entity. Returns +false+ on failure.
         | 
| 952 | 
            +
             * - name: the name of the DTD entity
         | 
| 953 | 
            +
             * - publicId: the public identifier, which is an alternative to the system identifier
         | 
| 954 | 
            +
             * - systemId: the system identifier, which is the URI of the DTD
         | 
| 955 | 
            +
             * - ndataid: the xml notation name
         | 
| 956 | 
            +
             * - pe: +true+ if this is a parameter entity (to be used only in the DTD
         | 
| 957 | 
            +
             * itself), +false+ if not
         | 
| 958 | 
            +
             */
         | 
| 959 | 
            +
            static VALUE rxml_writer_write_dtd_external_entity(VALUE self, VALUE name, VALUE pubid, VALUE sysid, VALUE ndataid, VALUE pe)
         | 
| 960 | 
            +
            {
         | 
| 961 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 962 | 
            +
                VALUE rubyStrings[] =  {name, pubid, sysid, ndataid};
         | 
| 963 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL, NULL};
         | 
| 964 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 965 | 
            +
                int result = xmlTextWriterWriteDTDExternalEntity(rwo->writer, RB_TEST(pe), xmlStrings[0], xmlStrings[1], xmlStrings[2], xmlStrings[3]);
         | 
| 966 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 967 | 
            +
            }
         | 
| 968 | 
            +
             | 
| 969 | 
            +
            /* call-seq:
         | 
| 970 | 
            +
             *    writer.write_dtd_external_entity_contents(publicId, systemId, ndataid) -> (true|false)
         | 
| 971 | 
            +
             *
         | 
| 972 | 
            +
             * Writes the contents of a DTD external entity, all at once. Returns +false+ on failure.
         | 
| 973 | 
            +
             */
         | 
| 974 | 
            +
            static VALUE rxml_writer_write_dtd_external_entity_contents(VALUE self, VALUE pubid, VALUE sysid, VALUE ndataid)
         | 
| 975 | 
            +
            {
         | 
| 976 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 977 | 
            +
                VALUE rubyStrings[] =  {pubid, sysid, ndataid,};
         | 
| 978 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL};
         | 
| 979 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 980 | 
            +
                int result = xmlTextWriterWriteDTDExternalEntityContents(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2]);
         | 
| 981 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 982 | 
            +
            }
         | 
| 983 | 
            +
             | 
| 984 | 
            +
            /* call-seq:
         | 
| 985 | 
            +
             *    writer.write_dtd_internal_entity(name, content, pe) -> (true|false)
         | 
| 986 | 
            +
             *
         | 
| 987 | 
            +
             * Writes a DTD internal entity, all at once. Returns +false+ on failure.
         | 
| 988 | 
            +
             *
         | 
| 989 | 
            +
             * Examples:
         | 
| 990 | 
            +
             *   writer.write_dtd_entity 'Shape', '(rect|circle|poly|default)', true
         | 
| 991 | 
            +
             *     #=> <!ENTITY % Shape "(rect|circle|poly|default)">
         | 
| 992 | 
            +
             *   writer.write_dtd_entity 'delta', 'δ', false
         | 
| 993 | 
            +
             *     #=> <!ENTITY delta "δ">
         | 
| 994 | 
            +
             */
         | 
| 995 | 
            +
            static VALUE rxml_writer_write_dtd_internal_entity(VALUE self, VALUE name, VALUE content, VALUE pe)
         | 
| 996 | 
            +
            {
         | 
| 997 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 998 | 
            +
                VALUE rubyStrings[] =  {name, content};
         | 
| 999 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL};
         | 
| 1000 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 1001 | 
            +
                int result = xmlTextWriterWriteDTDInternalEntity(rwo->writer, RB_TEST(pe), xmlStrings[0], xmlStrings[1]);
         | 
| 1002 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 1003 | 
            +
            }
         | 
| 1004 | 
            +
             | 
| 1005 | 
            +
            /* call-seq:
         | 
| 1006 | 
            +
             *    writer.write_dtd_notation(name, publicId, systemId) -> (true|false)
         | 
| 1007 | 
            +
             *
         | 
| 1008 | 
            +
             * Writes a DTD entity, all at once. Returns +false+ on failure.
         | 
| 1009 | 
            +
             */
         | 
| 1010 | 
            +
            static VALUE rxml_writer_write_dtd_notation(VALUE self, VALUE name, VALUE pubid, VALUE sysid)
         | 
| 1011 | 
            +
            {
         | 
| 1012 | 
            +
                rxml_writer_object* rwo = rxml_textwriter_get(self);
         | 
| 1013 | 
            +
                VALUE rubyStrings[] =  {name, pubid, sysid};
         | 
| 1014 | 
            +
                const xmlChar* xmlStrings[] =  {NULL, NULL, NULL};
         | 
| 1015 | 
            +
                encodeStrings(rwo->encoding, sizeof(rubyStrings)/sizeof(VALUE), rubyStrings, xmlStrings);
         | 
| 1016 | 
            +
                int result = xmlTextWriterWriteDTDNotation(rwo->writer, xmlStrings[0], xmlStrings[1], xmlStrings[2]);
         | 
| 1017 | 
            +
                return (result == -1 ? Qfalse : Qtrue);
         | 
| 1018 | 
            +
            }
         | 
| 1019 | 
            +
             | 
| 1020 | 
            +
            #if LIBXML_VERSION >= 20900
         | 
| 1021 | 
            +
            /* call-seq:
         | 
| 1022 | 
            +
             *    writer.set_quote_char(...) -> (true|false)
         | 
| 1023 | 
            +
             *
         | 
| 1024 | 
            +
             * Sets the character used to quote attributes. Returns +false+ on failure.
         | 
| 1025 | 
            +
             *
         | 
| 1026 | 
            +
             * Notes:
         | 
| 1027 | 
            +
             * - only " (default) and ' characters are valid
         | 
| 1028 | 
            +
             * - availability: libxml2 >= 2.9.0
         | 
| 1029 | 
            +
             */
         | 
| 1030 | 
            +
            static VALUE rxml_writer_set_quote_char(VALUE self, VALUE quotechar)
         | 
| 1031 | 
            +
            {
         | 
| 1032 | 
            +
                int ret;
         | 
| 1033 | 
            +
                const char* xquotechar;
         | 
| 1034 | 
            +
                rxml_writer_object* rwo;
         | 
| 1035 | 
            +
             | 
| 1036 | 
            +
                rwo = rxml_textwriter_get(self);
         | 
| 1037 | 
            +
                xquotechar = StringValueCStr(quotechar);
         | 
| 1038 | 
            +
                ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)xquotechar[0]);
         | 
| 1039 | 
            +
             | 
| 1040 | 
            +
                return (-1 == ret ? Qfalse : Qtrue);
         | 
| 1041 | 
            +
            }
         | 
| 1042 | 
            +
            #endif /* LIBXML_VERSION >= 20900 */
         | 
| 1043 | 
            +
             | 
| 1044 | 
            +
            #endif /* LIBXML_WRITER_ENABLED */
         | 
| 1045 | 
            +
             | 
| 1046 | 
            +
             | 
| 1047 | 
            +
            /* grep -P 'xmlTextWriter(Start|End|Write)(?!DTD|V?Format)[^(]+' /usr/include/libxml2/libxml/xmlwriter.h */
         | 
| 1048 | 
            +
            void rxml_init_writer(void)
         | 
| 1049 | 
            +
            {
         | 
| 1050 | 
            +
                sEncoding = ID2SYM(rb_intern("encoding"));
         | 
| 1051 | 
            +
                sStandalone = ID2SYM(rb_intern("standalone"));
         | 
| 1052 | 
            +
             | 
| 1053 | 
            +
                cXMLWriter = rb_define_class_under(mXML, "Writer", rb_cObject);
         | 
| 1054 | 
            +
                rb_undef_alloc_func(cXMLWriter);
         | 
| 1055 | 
            +
             | 
| 1056 | 
            +
            #ifdef LIBXML_WRITER_ENABLED
         | 
| 1057 | 
            +
                rb_define_singleton_method(cXMLWriter, "io", rxml_writer_io, 1);
         | 
| 1058 | 
            +
                rb_define_singleton_method(cXMLWriter, "file", rxml_writer_file, 1);
         | 
| 1059 | 
            +
                rb_define_singleton_method(cXMLWriter, "document", rxml_writer_doc, 0);
         | 
| 1060 | 
            +
                rb_define_singleton_method(cXMLWriter, "string", rxml_writer_string, 0);
         | 
| 1061 | 
            +
             | 
| 1062 | 
            +
                /* misc */
         | 
| 1063 | 
            +
            #if LIBXML_VERSION >= 20605
         | 
| 1064 | 
            +
                rb_define_method(cXMLWriter, "set_indent", rxml_writer_set_indent, 1);
         | 
| 1065 | 
            +
                rb_define_method(cXMLWriter, "set_indent_string", rxml_writer_set_indent_string, 1);
         | 
| 1066 | 
            +
            #endif /* LIBXML_VERSION >= 20605 */
         | 
| 1067 | 
            +
            #if LIBXML_VERSION >= 20900
         | 
| 1068 | 
            +
                rb_define_method(cXMLWriter, "set_quote_char", rxml_writer_set_quote_char, 1);
         | 
| 1069 | 
            +
            #endif  /* LIBXML_VERSION >= 20900 */
         | 
| 1070 | 
            +
                rb_define_method(cXMLWriter, "flush", rxml_writer_flush, -1);
         | 
| 1071 | 
            +
                rb_define_method(cXMLWriter, "start_dtd", rxml_writer_start_dtd, -1);
         | 
| 1072 | 
            +
                rb_define_method(cXMLWriter, "start_dtd_entity", rxml_writer_start_dtd_entity, -1);
         | 
| 1073 | 
            +
                rb_define_method(cXMLWriter, "start_dtd_attlist", rxml_writer_start_dtd_attlist, 1);
         | 
| 1074 | 
            +
                rb_define_method(cXMLWriter, "start_dtd_element", rxml_writer_start_dtd_element, 1);
         | 
| 1075 | 
            +
                rb_define_method(cXMLWriter, "write_dtd", rxml_writer_write_dtd, -1);
         | 
| 1076 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_attlist", rxml_writer_write_dtd_attlist, 2);
         | 
| 1077 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_element", rxml_writer_write_dtd_element, 2);
         | 
| 1078 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_entity", rxml_writer_write_dtd_entity, 6);
         | 
| 1079 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_external_entity", rxml_writer_write_dtd_external_entity, 5);
         | 
| 1080 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_external_entity_contents", rxml_writer_write_dtd_external_entity_contents, 3);
         | 
| 1081 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_internal_entity", rxml_writer_write_dtd_internal_entity, 3);
         | 
| 1082 | 
            +
                rb_define_method(cXMLWriter, "write_dtd_notation", rxml_writer_write_dtd_notation, 3);
         | 
| 1083 | 
            +
                rb_define_method(cXMLWriter, "end_dtd", rxml_writer_end_dtd, 0);
         | 
| 1084 | 
            +
                rb_define_method(cXMLWriter, "end_dtd_entity", rxml_writer_end_dtd_entity, 0);
         | 
| 1085 | 
            +
                rb_define_method(cXMLWriter, "end_dtd_attlist", rxml_writer_end_dtd_attlist, 0);
         | 
| 1086 | 
            +
                rb_define_method(cXMLWriter, "end_dtd_element", rxml_writer_end_dtd_element, 0);
         | 
| 1087 | 
            +
             | 
| 1088 | 
            +
                /* tag by parts */
         | 
| 1089 | 
            +
                rb_define_method(cXMLWriter, "write_raw", rxml_writer_write_raw, 1);
         | 
| 1090 | 
            +
                rb_define_method(cXMLWriter, "write_string", rxml_writer_write_string, 1);
         | 
| 1091 | 
            +
             | 
| 1092 | 
            +
                rb_define_method(cXMLWriter, "start_cdata", rxml_writer_start_cdata, 0);
         | 
| 1093 | 
            +
                rb_define_method(cXMLWriter, "end_cdata", rxml_writer_end_cdata, 0);
         | 
| 1094 | 
            +
                rb_define_method(cXMLWriter, "start_attribute", rxml_writer_start_attribute, 1);
         | 
| 1095 | 
            +
                rb_define_method(cXMLWriter, "start_attribute_ns", rxml_writer_start_attribute_ns, -1);
         | 
| 1096 | 
            +
                rb_define_method(cXMLWriter, "end_attribute", rxml_writer_end_attribute, 0);
         | 
| 1097 | 
            +
                rb_define_method(cXMLWriter, "start_element", rxml_writer_start_element, 1);
         | 
| 1098 | 
            +
                rb_define_method(cXMLWriter, "start_element_ns", rxml_writer_start_element_ns, -1);
         | 
| 1099 | 
            +
                rb_define_method(cXMLWriter, "end_element", rxml_writer_end_element, 0);
         | 
| 1100 | 
            +
                rb_define_method(cXMLWriter, "full_end_element", rxml_writer_full_end_element, 0);
         | 
| 1101 | 
            +
                rb_define_method(cXMLWriter, "start_document", rxml_writer_start_document, -1);
         | 
| 1102 | 
            +
                rb_define_method(cXMLWriter, "end_document", rxml_writer_end_document, 0);
         | 
| 1103 | 
            +
            #if LIBXML_VERSION >= 20607
         | 
| 1104 | 
            +
                rb_define_method(cXMLWriter, "start_comment", rxml_writer_start_comment, 0);
         | 
| 1105 | 
            +
                rb_define_method(cXMLWriter, "end_comment", rxml_writer_end_comment, 0);
         | 
| 1106 | 
            +
            #endif /* LIBXML_VERSION >= 20607 */
         | 
| 1107 | 
            +
                rb_define_method(cXMLWriter, "start_pi", rxml_writer_start_pi, 1);
         | 
| 1108 | 
            +
                rb_define_method(cXMLWriter, "end_pi", rxml_writer_end_pi, 0);
         | 
| 1109 | 
            +
             | 
| 1110 | 
            +
                /* full tag at once */
         | 
| 1111 | 
            +
                rb_define_method(cXMLWriter, "write_attribute", rxml_writer_write_attribute, 2);
         | 
| 1112 | 
            +
                rb_define_method(cXMLWriter, "write_attribute_ns", rxml_writer_write_attribute_ns, -1);
         | 
| 1113 | 
            +
                rb_define_method(cXMLWriter, "write_comment", rxml_writer_write_comment, 1);
         | 
| 1114 | 
            +
                rb_define_method(cXMLWriter, "write_cdata", rxml_writer_write_cdata, 1);
         | 
| 1115 | 
            +
                rb_define_method(cXMLWriter, "write_element", rxml_writer_write_element, -1);
         | 
| 1116 | 
            +
                rb_define_method(cXMLWriter, "write_element_ns", rxml_writer_write_element_ns, -1);
         | 
| 1117 | 
            +
                rb_define_method(cXMLWriter, "write_pi", rxml_writer_write_pi, 2);
         | 
| 1118 | 
            +
             | 
| 1119 | 
            +
                rb_define_method(cXMLWriter, "result", rxml_writer_result, 0);
         | 
| 1120 | 
            +
             | 
| 1121 | 
            +
                rb_undef_method(CLASS_OF(cXMLWriter), "new");
         | 
| 1122 | 
            +
            #endif
         | 
| 1123 | 
            +
            }
         | 
| 1124 | 
            +
             |