Skip to content

Commit

Permalink
Updated docs for DTD creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfis committed Jan 8, 2024
1 parent b0a4e20 commit b11e90f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 89 deletions.
171 changes: 85 additions & 86 deletions libxml-ruby/LibXML/XML/Dtd.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,133 +127,132 @@ <h3>Public Class Methods</h3>
<div class="method-header">
<div class="method-heading">
<span class="method-callseq">
XML::Dtd.new(&quot;DTD string&quot;) &rarr; dtd
XML::Dtd.new(dtd_string) &rarr; dtd
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
XML::Dtd.new(&quot;public&quot;, &quot;system&quot;) &rarr; dtd
XML::Dtd.new(external_id, system_id) &rarr; dtd
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
XML::Dtd.new(&quot;name&quot;, &quot;public&quot;, &quot;system&quot;, document) &rarr; external subset dtd
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
XML::Dtd.new(&quot;name&quot;, &quot;public&quot;, &quot;system&quot;, document, false) &rarr; internal subset dtd
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
XML::Dtd.new(&quot;name&quot;, &quot;public&quot;, &quot;system&quot;, document, true) &rarr; internal subset dtd
XML::Dtd.new(external_id, system_id, name, document, internal) &rarr; dtd
</span>
</div>
</div>

<div class="method-description">
<p>Create a new <a href="Dtd.html"><code>Dtd</code></a> from the specified public and system identifiers.</p>
<p>Create a new <a href="Dtd.html"><code>Dtd</code></a> from the specified public and system identifiers:</p>

<pre>* The first usage creates a DTD from a string and requires 1 parameter.
* The second usage loads and parses an external DTD and requires 2 parameters.
* The third usage creates a new internal or external DTD and requires 3 parameters and 2 optional parameters.
It then attaches the DTD to the specified document if it is not nil</pre>

<p>Parameters:</p>

<pre>dtd_string - A string that contains a complete DTD
external_id - A string that specifies the DTD&#39;s external name. For example, &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
system_id - A string that specififies the DTD&#39;s system name. For example, &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;
name - A string that specifies the DTD&#39;s name. For example &quot;xhtml1&quot;.
document - A xml document.
internal - Boolean value indicating whether this is an internal or external DTD. Optional. If not specified
then external is assumed.</pre>

<div class="method-source-code" id="new-source">
<pre>static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE external, system, dtd_string;
xmlParserInputBufferPtr buffer;
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
xmlChar *new_string;
xmlDtdPtr xdtd;
VALUE external, system;

// 1 argument -- string --&gt; parsujeme jako dtd
// 2 arguments -- public, system --&gt; bude se hledat
// 3 arguments -- public, system, name --&gt; creates an external subset (any parameter may be nil)
// 4 arguments -- public, system, name, doc --&gt; creates an external subset (any parameter may be nil)
// 5 arguments -- public, system, name, doc, true --&gt; creates an internal subset (all but last parameter may be nil)
switch (argc)
{
case 3:
case 4:
case 5: {
VALUE name, doc, internal;
const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
xmlDocPtr xdoc = NULL;
case 3:
case 4:
case 5:
{
const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
xmlDocPtr xdoc = NULL;

rb_scan_args(argc, argv, &quot;32&quot;, &amp;external, &amp;system, &amp;name, &amp;doc, &amp;internal);
VALUE name, doc, internal;
rb_scan_args(argc, argv, &quot;32&quot;, &amp;external, &amp;system, &amp;name, &amp;doc, &amp;internal);

if (external != Qnil) {
Check_Type(external, T_STRING);
xpublic = (const xmlChar*) StringValuePtr(external);
}
if (system != Qnil) {
Check_Type(system, T_STRING);
xsystem = (const xmlChar*) StringValuePtr(system);
}
if (name != Qnil) {
Check_Type(name, T_STRING);
xname = (const xmlChar*) StringValuePtr(name);
}
if (doc != Qnil) {
if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
rb_raise(rb_eTypeError, &quot;Must pass an LibXML::XML::Document object&quot;);
Data_Get_Struct(doc, xmlDoc, xdoc);
}
Check_Type(external, T_STRING);
xpublic = (const xmlChar*) StringValuePtr(external);

if (internal == Qnil || internal == Qfalse)
xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
else
xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
Check_Type(system, T_STRING);
xsystem = (const xmlChar*) StringValuePtr(system);

if (xdtd == NULL)
rxml_raise(xmlGetLastError());
Check_Type(name, T_STRING);
xname = (const xmlChar*) StringValuePtr(name);

/* Document will free this dtd now. */
RDATA(self)-&gt;dfree = NULL;
DATA_PTR(self) = xdtd;
if (doc != Qnil)
{
if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
rb_raise(rb_eTypeError, &quot;Must pass an LibXML::XML::Document object&quot;);
Data_Get_Struct(doc, xmlDoc, xdoc);
}

xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
}
break;
if (internal == Qnil || internal == Qfalse)
xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
else
xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);

case 2:
rb_scan_args(argc, argv, &quot;20&quot;, &amp;external, &amp;system);
if (xdtd == NULL)
rxml_raise(xmlGetLastError());

Check_Type(external, T_STRING);
Check_Type(system, T_STRING);
/* The document will free the dtd so Ruby should not */
RDATA(self)-&gt;dfree = NULL;
DATA_PTR(self) = xdtd;

xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
(xmlChar*) StringValuePtr(system));
xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
}
break;

if (xdtd == NULL)
rxml_raise(xmlGetLastError());
case 2:
{
rb_scan_args(argc, argv, &quot;20&quot;, &amp;external, &amp;system);

DATA_PTR(self) = xdtd;
Check_Type(external, T_STRING);
Check_Type(system, T_STRING);

xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
break;
xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system));

case 1:
rb_scan_args(argc, argv, &quot;10&quot;, &amp;dtd_string);
Check_Type(dtd_string, T_STRING);
if (xdtd == NULL)
rxml_raise(xmlGetLastError());

/* Note that buffer is freed by xmlParserInputBufferPush*/
buffer = xmlAllocParserInputBuffer(enc);
new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
(const char*) new_string);
DATA_PTR(self) = xdtd;

xdtd = xmlIOParseDTD(NULL, buffer, enc);
xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
break;
}
case 1:
{
VALUE dtd_string;
rb_scan_args(argc, argv, &quot;10&quot;, &amp;dtd_string);
Check_Type(dtd_string, T_STRING);

if (xdtd == NULL)
rxml_raise(xmlGetLastError());
/* Note that buffer is freed by xmlParserInputBufferPush*/
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
xmlParserInputBufferPtr buffer = xmlAllocParserInputBuffer(enc);
xmlChar *new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
(const char*) new_string);

xmlFree(new_string);
xdtd = xmlIOParseDTD(NULL, buffer, enc);

DATA_PTR(self) = xdtd;
break;
if (xdtd == NULL)
rxml_raise(xmlGetLastError());

default:
rb_raise(rb_eArgError, &quot;wrong number of arguments&quot;);
xmlFree(new_string);

DATA_PTR(self) = xdtd;
break;
}
default:
rb_raise(rb_eArgError, &quot;wrong number of arguments&quot;);
}

return self;
Expand Down
4 changes: 2 additions & 2 deletions libxml-ruby/created.rid
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Mon, 08 Jan 2024 12:02:50 -0800
Mon, 08 Jan 2024 13:29:37 -0800
ext/libxml/libxml.c Wed, 28 Dec 2022 05:02:38 -0800
ext/libxml/ruby_xml.c Sun, 07 Jan 2024 18:19:55 -0800
ext/libxml/ruby_xml_attr.c Sat, 15 Jan 2022 16:07:33 -0800
ext/libxml/ruby_xml_attr_decl.c Sat, 04 Nov 2023 17:22:35 -0700
ext/libxml/ruby_xml_attributes.c Sat, 04 Nov 2023 17:22:35 -0700
ext/libxml/ruby_xml_cbg.c Wed, 28 Dec 2022 04:30:41 -0800
ext/libxml/ruby_xml_document.c Sun, 07 Jan 2024 20:04:17 -0800
ext/libxml/ruby_xml_dtd.c Sun, 07 Jan 2024 20:04:17 -0800
ext/libxml/ruby_xml_dtd.c Mon, 08 Jan 2024 13:27:53 -0800
ext/libxml/ruby_xml_encoding.c Sun, 30 Apr 2023 21:34:00 -0700
ext/libxml/ruby_xml_error.c Sun, 07 Jan 2024 21:53:55 -0800
ext/libxml/ruby_xml_html_parser.c Sun, 16 Oct 2022 22:49:51 -0700
Expand Down
2 changes: 1 addition & 1 deletion libxml-ruby/js/search_index.js

Large diffs are not rendered by default.

Binary file modified libxml-ruby/js/search_index.js.gz
Binary file not shown.

0 comments on commit b11e90f

Please sign in to comment.