<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: Nokogiri::XML::Document</title>

	<link rel="stylesheet" href="../../rdoc.css" type="text/css" media="screen" />

	<script src="../../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../../index.html">Home</a>
          <a href="../../index.html#classes">Classes</a>
          <a href="../../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../../lib/nokogiri/xml/document_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/nokogiri/xml/document.rb">lib/nokogiri/xml/document.rb</a></li>
					
						<li><a href="../../ext/nokogiri/xml_sax_parser_c.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="ext/nokogiri/xml_sax_parser.c">ext/nokogiri/xml_sax_parser.c</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link"><a href="Node.html">Nokogiri::XML::Node</a></p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-new">::new</a></li>
					
					<li><a href="#method-c-parse">::parse</a></li>
					
					<li><a href="#method-c-read_io">::read_io</a></li>
					
					<li><a href="#method-c-read_memory">::read_memory</a></li>
					
					<li><a href="#method-i-%3C%3C">#<<</a></li>
					
					<li><a href="#method-i-add_child">#add_child</a></li>
					
					<li><a href="#method-i-clone">#clone</a></li>
					
					<li><a href="#method-i-collect_namespaces">#collect_namespaces</a></li>
					
					<li><a href="#method-i-create_cdata">#create_cdata</a></li>
					
					<li><a href="#method-i-create_element">#create_element</a></li>
					
					<li><a href="#method-i-create_entity">#create_entity</a></li>
					
					<li><a href="#method-i-create_text_node">#create_text_node</a></li>
					
					<li><a href="#method-i-decorate">#decorate</a></li>
					
					<li><a href="#method-i-decorators">#decorators</a></li>
					
					<li><a href="#method-i-document">#document</a></li>
					
					<li><a href="#method-i-dup">#dup</a></li>
					
					<li><a href="#method-i-encoding">#encoding</a></li>
					
					<li><a href="#method-i-encoding%3D">#encoding=</a></li>
					
					<li><a href="#method-i-fragment">#fragment</a></li>
					
					<li><a href="#method-i-implied_xpath_context">#implied_xpath_context</a></li>
					
					<li><a href="#method-i-inspect_attributes">#inspect_attributes</a></li>
					
					<li><a href="#method-i-name">#name</a></li>
					
					<li><a href="#method-i-namespaces">#namespaces</a></li>
					
					<li><a href="#method-i-remove_namespaces%21">#remove_namespaces!</a></li>
					
					<li><a href="#method-i-root">#root</a></li>
					
					<li><a href="#method-i-root%3D">#root=</a></li>
					
					<li><a href="#method-i-slop%21">#slop!</a></li>
					
					<li><a href="#method-i-url">#url</a></li>
					
					<li><a href="#method-i-validate">#validate</a></li>
					
					<li><a href="#method-i-version">#version</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="../../CHANGELOG_ja_rdoc.html">CHANGELOG.ja.rdoc</a></li>
				
					<li class="file"><a href="../../CHANGELOG_rdoc.html">CHANGELOG.rdoc</a></li>
				
					<li class="file"><a href="../../Manifest_txt.html">Manifest.txt</a></li>
				
					<li class="file"><a href="../../README_ja_rdoc.html">README.ja.rdoc</a></li>
				
					<li class="file"><a href="../../README_rdoc.html">README.rdoc</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../../Nokogiri.html">Nokogiri</a></li>
				
					<li><a href="../../Nokogiri/CSS.html">Nokogiri::CSS</a></li>
				
					<li><a href="../../Nokogiri/CSS/GeneratedParser.html">Nokogiri::CSS::GeneratedParser</a></li>
				
					<li><a href="../../Nokogiri/CSS/GeneratedTokenizer.html">Nokogiri::CSS::GeneratedTokenizer</a></li>
				
					<li><a href="../../Nokogiri/CSS/GeneratedTokenizer/ScanError.html">Nokogiri::CSS::GeneratedTokenizer::ScanError</a></li>
				
					<li><a href="../../Nokogiri/CSS/Node.html">Nokogiri::CSS::Node</a></li>
				
					<li><a href="../../Nokogiri/CSS/Parser.html">Nokogiri::CSS::Parser</a></li>
				
					<li><a href="../../Nokogiri/CSS/SyntaxError.html">Nokogiri::CSS::SyntaxError</a></li>
				
					<li><a href="../../Nokogiri/CSS/Tokenizer.html">Nokogiri::CSS::Tokenizer</a></li>
				
					<li><a href="../../Nokogiri/Decorators.html">Nokogiri::Decorators</a></li>
				
					<li><a href="../../Nokogiri/Decorators/Slop.html">Nokogiri::Decorators::Slop</a></li>
				
					<li><a href="../../Nokogiri/EncodingHandler.html">Nokogiri::EncodingHandler</a></li>
				
					<li><a href="../../Nokogiri/HTML.html">Nokogiri::HTML</a></li>
				
					<li><a href="../../Nokogiri/HTML/Builder.html">Nokogiri::HTML::Builder</a></li>
				
					<li><a href="../../Nokogiri/HTML/Document.html">Nokogiri::HTML::Document</a></li>
				
					<li><a href="../../Nokogiri/HTML/DocumentFragment.html">Nokogiri::HTML::DocumentFragment</a></li>
				
					<li><a href="../../Nokogiri/HTML/ElementDescription.html">Nokogiri::HTML::ElementDescription</a></li>
				
					<li><a href="../../Nokogiri/HTML/EntityDescription.html">Nokogiri::HTML::EntityDescription</a></li>
				
					<li><a href="../../Nokogiri/HTML/EntityLookup.html">Nokogiri::HTML::EntityLookup</a></li>
				
					<li><a href="../../Nokogiri/HTML/SAX.html">Nokogiri::HTML::SAX</a></li>
				
					<li><a href="../../Nokogiri/HTML/SAX/Parser.html">Nokogiri::HTML::SAX::Parser</a></li>
				
					<li><a href="../../Nokogiri/HTML/SAX/ParserContext.html">Nokogiri::HTML::SAX::ParserContext</a></li>
				
					<li><a href="../../Nokogiri/SyntaxError.html">Nokogiri::SyntaxError</a></li>
				
					<li><a href="../../Nokogiri/XML.html">Nokogiri::XML</a></li>
				
					<li><a href="../../Nokogiri/XML/Attr.html">Nokogiri::XML::Attr</a></li>
				
					<li><a href="../../Nokogiri/XML/AttributeDecl.html">Nokogiri::XML::AttributeDecl</a></li>
				
					<li><a href="../../Nokogiri/XML/Builder.html">Nokogiri::XML::Builder</a></li>
				
					<li><a href="../../Nokogiri/XML/CDATA.html">Nokogiri::XML::CDATA</a></li>
				
					<li><a href="../../Nokogiri/XML/CharacterData.html">Nokogiri::XML::CharacterData</a></li>
				
					<li><a href="../../Nokogiri/XML/Comment.html">Nokogiri::XML::Comment</a></li>
				
					<li><a href="../../Nokogiri/XML/DTD.html">Nokogiri::XML::DTD</a></li>
				
					<li><a href="../../Nokogiri/XML/Document.html">Nokogiri::XML::Document</a></li>
				
					<li><a href="../../Nokogiri/XML/DocumentFragment.html">Nokogiri::XML::DocumentFragment</a></li>
				
					<li><a href="../../Nokogiri/XML/Element.html">Nokogiri::XML::Element</a></li>
				
					<li><a href="../../Nokogiri/XML/ElementContent.html">Nokogiri::XML::ElementContent</a></li>
				
					<li><a href="../../Nokogiri/XML/ElementDecl.html">Nokogiri::XML::ElementDecl</a></li>
				
					<li><a href="../../Nokogiri/XML/EntityDecl.html">Nokogiri::XML::EntityDecl</a></li>
				
					<li><a href="../../Nokogiri/XML/EntityReference.html">Nokogiri::XML::EntityReference</a></li>
				
					<li><a href="../../Nokogiri/XML/Namespace.html">Nokogiri::XML::Namespace</a></li>
				
					<li><a href="../../Nokogiri/XML/Node.html">Nokogiri::XML::Node</a></li>
				
					<li><a href="../../Nokogiri/XML/Node/SaveOptions.html">Nokogiri::XML::Node::SaveOptions</a></li>
				
					<li><a href="../../Nokogiri/XML/NodeSet.html">Nokogiri::XML::NodeSet</a></li>
				
					<li><a href="../../Nokogiri/XML/Notation.html">Nokogiri::XML::Notation</a></li>
				
					<li><a href="../../Nokogiri/XML/PP.html">Nokogiri::XML::PP</a></li>
				
					<li><a href="../../Nokogiri/XML/PP/CharacterData.html">Nokogiri::XML::PP::CharacterData</a></li>
				
					<li><a href="../../Nokogiri/XML/PP/Node.html">Nokogiri::XML::PP::Node</a></li>
				
					<li><a href="../../Nokogiri/XML/ParseOptions.html">Nokogiri::XML::ParseOptions</a></li>
				
					<li><a href="../../Nokogiri/XML/ProcessingInstruction.html">Nokogiri::XML::ProcessingInstruction</a></li>
				
					<li><a href="../../Nokogiri/XML/Reader.html">Nokogiri::XML::Reader</a></li>
				
					<li><a href="../../Nokogiri/XML/RelaxNG.html">Nokogiri::XML::RelaxNG</a></li>
				
					<li><a href="../../Nokogiri/XML/SAX.html">Nokogiri::XML::SAX</a></li>
				
					<li><a href="../../Nokogiri/XML/SAX/Document.html">Nokogiri::XML::SAX::Document</a></li>
				
					<li><a href="../../Nokogiri/XML/SAX/Parser.html">Nokogiri::XML::SAX::Parser</a></li>
				
					<li><a href="../../Nokogiri/XML/SAX/Parser/Attribute.html">Nokogiri::XML::SAX::Parser::Attribute</a></li>
				
					<li><a href="../../Nokogiri/XML/SAX/ParserContext.html">Nokogiri::XML::SAX::ParserContext</a></li>
				
					<li><a href="../../Nokogiri/XML/SAX/PushParser.html">Nokogiri::XML::SAX::PushParser</a></li>
				
					<li><a href="../../Nokogiri/XML/Schema.html">Nokogiri::XML::Schema</a></li>
				
					<li><a href="../../Nokogiri/XML/SyntaxError.html">Nokogiri::XML::SyntaxError</a></li>
				
					<li><a href="../../Nokogiri/XML/Text.html">Nokogiri::XML::Text</a></li>
				
					<li><a href="../../Nokogiri/XML/XPath.html">Nokogiri::XML::XPath</a></li>
				
					<li><a href="../../Nokogiri/XML/XPath/SyntaxError.html">Nokogiri::XML::XPath::SyntaxError</a></li>
				
					<li><a href="../../Nokogiri/XML/XPathContext.html">Nokogiri::XML::XPathContext</a></li>
				
					<li><a href="../../Nokogiri/XSLT.html">Nokogiri::XSLT</a></li>
				
					<li><a href="../../Nokogiri/XSLT/Stylesheet.html">Nokogiri::XSLT::Stylesheet</a></li>
				
					<li><a href="../../XSD/XMLParser/Nokogiri.html">XSD::XMLParser::Nokogiri</a></li>
				
					<li><a href="../../Object.html">Object</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">Nokogiri::XML::Document</h1>

		<div id="description">
			<p>
<a href="Document.html">Nokogiri::XML::Document</a> is the main entry point
for dealing with <a href="../XML.html">XML</a> documents.  The <a
href="Document.html">Document</a> is created by parsing an <a
href="../XML.html">XML</a> document. See <a
href="../../Nokogiri.html">Nokogiri</a>.XML()
</p>
<p>
For searching a <a href="Document.html">Document</a>, see <a
href="Node.html#method-i-css">Nokogiri::XML::Node#css</a> and <a
href="Node.html#method-i-xpath">Nokogiri::XML::Node#xpath</a>
</p>

		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		
		<div id="attribute-method-details" class="method-section section">
			<h3 class="section-header">Attributes</h3>

			
			<div id="errors-attribute-method" class="method-detail">
				<a name="errors"></a>
				
				<a name="errors="></a>
				
				<div class="method-heading attribute-method-heading">
					<span class="method-name">errors</span><span
						class="attribute-access-type">[RW]</span>
				</div>

				<div class="method-description">
				
				<p>
A list of <a href="SyntaxError.html">Nokogiri::XML::SyntaxError</a> found
when parsing a document
</p>
				
				</div>
			</div>
			
		</div>
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="new-method" class="method-detail ">
				<a name="method-c-new"></a>

				<div class="method-heading">
				
					<span class="method-callseq">new(version = default)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a new document with <tt>version</tt> (defaults to &#8220;1.0&#8220;)
</p>
					

					
					<div class="method-source-code"
						id="new-source">
<pre>
static VALUE new(int argc, VALUE *argv, VALUE klass)
{
  xmlDocPtr doc;
  VALUE version, rest, rb_doc ;

  rb_scan_args(argc, argv, &quot;0*&quot;, &amp;rest);
  version = rb_ary_entry(rest, (long)0);
  if (NIL_P(version)) version = rb_str_new2(&quot;1.0&quot;);

  doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
  rb_doc = Nokogiri_wrap_xml_document(klass, doc);
  rb_obj_call_init(rb_doc, argc, argv);
  return rb_doc ;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="parse-method" class="method-detail ">
				<a name="method-c-parse"></a>

				<div class="method-heading">
				
					<span class="method-name">parse</span><span
						class="method-args">(string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Parse an <a href="../XML.html">XML</a> file.  <tt>thing</tt> may be a
String, or any object that responds to <em>read</em> and <em>close</em>
such as an IO, or StringIO. <tt>url</tt> is resource where this document is
located.  <tt>encoding</tt> is the encoding that should be used when
processing the document. <tt>options</tt> is a number that sets options in
the parser, such as Nokogiri::XML::ParseOptions::RECOVER.  See the
constants in <a href="ParseOptions.html">Nokogiri::XML::ParseOptions</a>.
</p>
					

					
					<div class="method-source-code"
						id="parse-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 19</span>
19:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">string_or_io</span>, <span class="ruby-identifier">url</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">encoding</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = <span class="ruby-constant">ParseOptions</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_XML</span>, &amp;<span class="ruby-identifier">block</span>
20: 
21:         <span class="ruby-identifier">options</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">ParseOptions</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Fixnum</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">options</span>
22:         <span class="ruby-comment cmt"># Give the options to the user</span>
23:         <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">options</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
24: 
25:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string_or_io</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:read</span>)
26:           <span class="ruby-identifier">url</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">string_or_io</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:path</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">string_or_io</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
27:           <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read_io</span>(<span class="ruby-identifier">string_or_io</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">encoding</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">to_i</span>)
28:         <span class="ruby-keyword kw">end</span>
29: 
30:         <span class="ruby-comment cmt"># read_memory pukes on empty docs</span>
31:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">new</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string_or_io</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">string_or_io</span>.<span class="ruby-identifier">empty?</span>
32: 
33:         <span class="ruby-identifier">read_memory</span>(<span class="ruby-identifier">string_or_io</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">encoding</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">to_i</span>)
34:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="read-io-method" class="method-detail ">
				<a name="method-c-read_io"></a>

				<div class="method-heading">
				
					<span class="method-callseq">read_io(io, url, encoding, options)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a new document from an IO object
</p>
					

					
					<div class="method-source-code"
						id="read-io-source">
<pre>
static VALUE read_io( VALUE klass,
                      VALUE io,
                      VALUE url,
                      VALUE encoding,
                      VALUE options )
{
  const char * c_url    = NIL_P(url)      ? NULL : StringValuePtr(url);
  const char * c_enc    = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
  VALUE error_list      = rb_ary_new();
  VALUE document;
  xmlDocPtr doc;

  xmlResetLastError();
  xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);

  doc = xmlReadIO(
      (xmlInputReadCallback)io_read_callback,
      (xmlInputCloseCallback)io_close_callback,
      (void *)io,
      c_url,
      c_enc,
      (int)NUM2INT(options)
  );
  xmlSetStructuredErrorFunc(NULL, NULL);

  if(doc == NULL) {
    xmlErrorPtr error;

    xmlFreeDoc(doc);

    error = xmlGetLastError();
    if(error)
      rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
    else
      rb_raise(rb_eRuntimeError, &quot;Could not parse document&quot;);

    return Qnil;
  }

  document = Nokogiri_wrap_xml_document(klass, doc);
  rb_iv_set(document, &quot;@errors&quot;, error_list);
  return document;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="read-memory-method" class="method-detail ">
				<a name="method-c-read_memory"></a>

				<div class="method-heading">
				
					<span class="method-callseq">read_memory(string, url, encoding, options)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a new document from a String
</p>
					

					
					<div class="method-source-code"
						id="read-memory-source">
<pre>
static VALUE read_memory( VALUE klass,
                          VALUE string,
                          VALUE url,
                          VALUE encoding,
                          VALUE options )
{
  const char * c_buffer = StringValuePtr(string);
  const char * c_url    = NIL_P(url)      ? NULL : StringValuePtr(url);
  const char * c_enc    = NIL_P(encoding) ? NULL : StringValuePtr(encoding);
  int len               = (int)RSTRING_LEN(string);
  VALUE error_list      = rb_ary_new();
  VALUE document;
  xmlDocPtr doc;

  xmlResetLastError();
  xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
  doc = xmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
  xmlSetStructuredErrorFunc(NULL, NULL);

  if(doc == NULL) {
    xmlErrorPtr error;

    xmlFreeDoc(doc);

    error = xmlGetLastError();
    if(error)
      rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
    else
      rb_raise(rb_eRuntimeError, &quot;Could not parse document&quot;);

    return Qnil;
  }

  document = Nokogiri_wrap_xml_document(klass, doc);
  rb_iv_set(document, &quot;@errors&quot;, error_list);
  return document;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="--method" class="method-detail method-alias">
				<a name="method-i-%3C%3C"></a>

				<div class="method-heading">
				
					<span class="method-name">&lt;&lt;</span><span
						class="method-args">(child)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
				</div>

				

				
				<div class="aliases">
          Alias for: <a href="Document.html#method-i-add_child">add_child</a>
				</div>
				
			</div>

		
			<div id="add-child-method" class="method-detail ">
				<a name="method-i-add_child"></a>

				<div class="method-heading">
				
					<span class="method-name">add_child</span><span
						class="method-args">(child)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="add-child-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 197</span>
197:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_child</span> <span class="ruby-identifier">child</span>
198:         <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Document already has a root node&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">root</span>
199:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Node</span><span class="ruby-operator">::</span><span class="ruby-constant">DOCUMENT_FRAG_NODE</span>
200:           <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Document cannot have multiple root nodes&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
201:           <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">child</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">first</span>)
202:         <span class="ruby-keyword kw">else</span>
203:           <span class="ruby-keyword kw">super</span>
204:         <span class="ruby-keyword kw">end</span>
205:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				
				<div class="aliases">
					Also aliased as: <a href="Document.html#method-i-%3C%3C">&lt;&lt;</a>
				</div>
				

				
			</div>

		
			<div id="clone-method" class="method-detail method-alias">
				<a name="method-i-clone"></a>

				<div class="method-heading">
				
					<span class="method-name">clone</span><span
						class="method-args">(...)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
				</div>

				

				
				<div class="aliases">
          Alias for: <a href="Document.html#method-i-dup">dup</a>
				</div>
				
			</div>

		
			<div id="collect-namespaces-method" class="method-detail ">
				<a name="method-i-collect_namespaces"></a>

				<div class="method-heading">
				
					<span class="method-name">collect_namespaces</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Recursively get all namespaces from this node and its subtree and return
them as a hash.
</p>
<p>
For example, given this document:
</p>
<pre>
  &lt;root xmlns:foo=&quot;bar&quot;&gt;
    &lt;bar xmlns:hello=&quot;world&quot; /&gt;
  &lt;/root&gt;
</pre>
<p>
This method will return:
</p>
<pre>
  { 'xmlns:foo' =&gt; 'bar', 'xmlns:hello' =&gt; 'world' }
</pre>
<p>
WARNING: this method will clobber duplicate names in the keys. For example,
given this document:
</p>
<pre>
  &lt;root xmlns:foo=&quot;bar&quot;&gt;
    &lt;bar xmlns:foo=&quot;baz&quot; /&gt;
  &lt;/root&gt;
</pre>
<p>
The hash returned will look like this: { &#8216;xmlns:foo&#8217; =>
&#8216;bar&#8217; }
</p>
<p>
Non-prefixed default namespaces (as in &#8220;xmlns=&#8221;) are not
included in the hash.
</p>
<p>
Note this is a very expensive operation in current implementation, as it
traverses the entire graph, and also has to bring each node accross the
libxml bridge into a ruby object.
</p>
					

					
					<div class="method-source-code"
						id="collect-namespaces-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 123</span>
123:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collect_namespaces</span>
124:         <span class="ruby-identifier">ns</span> = {}
125:         <span class="ruby-identifier">traverse</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span> <span class="ruby-identifier">ns</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">j</span>.<span class="ruby-identifier">namespaces</span>) }
126:         <span class="ruby-identifier">ns</span>
127:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="create-cdata-method" class="method-detail ">
				<a name="method-i-create_cdata"></a>

				<div class="method-heading">
				
					<span class="method-name">create_cdata</span><span
						class="method-args">(text)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a <a href="CDATA.html">CDATA</a> element containing <tt>text</tt>
</p>
					

					
					<div class="method-source-code"
						id="create-cdata-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 80</span>
80:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_cdata</span> <span class="ruby-identifier">text</span>
81:         <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">CDATA</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">text</span>.<span class="ruby-identifier">to_s</span>)
82:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="create-element-method" class="method-detail ">
				<a name="method-i-create_element"></a>

				<div class="method-heading">
				
					<span class="method-name">create_element</span><span
						class="method-args">(name, *args, &block)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create an element with <tt>name</tt>, and optionally setting the content
and attributes.
</p>
<pre>
  doc.create_element &quot;div&quot; # &lt;div&gt;&lt;/div&gt;
  doc.create_element &quot;div&quot;, :class =&gt; &quot;container&quot; # &lt;div class='container'&gt;&lt;/div&gt;
  doc.create_element &quot;div&quot;, &quot;contents&quot; # &lt;div&gt;contents&lt;/div&gt;
  doc.create_element &quot;div&quot;, &quot;contents&quot;, :class =&gt; &quot;container&quot; # &lt;div class='container'&gt;contents&lt;/div&gt;
  doc.create_element &quot;div&quot; { |node| node['class'] = &quot;container&quot; } # &lt;div class='container'&gt;&lt;/div&gt;</pre>
					

					
					<div class="method-source-code"
						id="create-element-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 53</span>
53:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_element</span> <span class="ruby-identifier">name</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>
54:         <span class="ruby-identifier">elm</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-keyword kw">self</span>, &amp;<span class="ruby-identifier">block</span>)
55:         <span class="ruby-identifier">args</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span>
56:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">arg</span>
57:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
58:             <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
59:               <span class="ruby-identifier">key</span> = <span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>
60:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^xmlns(:\w+)?$/</span>
61:                 <span class="ruby-identifier">ns_name</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;:&quot;</span>, <span class="ruby-value">2</span>)[<span class="ruby-value">1</span>]
62:                 <span class="ruby-identifier">elm</span>.<span class="ruby-identifier">add_namespace_definition</span> <span class="ruby-identifier">ns_name</span>, <span class="ruby-identifier">v</span>
63:                 <span class="ruby-keyword kw">next</span>
64:               <span class="ruby-keyword kw">end</span>
65:               <span class="ruby-identifier">elm</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_s</span>
66:             }
67:           <span class="ruby-keyword kw">else</span>
68:             <span class="ruby-identifier">elm</span>.<span class="ruby-identifier">content</span> = <span class="ruby-identifier">arg</span>
69:           <span class="ruby-keyword kw">end</span>
70:         <span class="ruby-keyword kw">end</span>
71:         <span class="ruby-identifier">elm</span>
72:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="create-entity-method" class="method-detail ">
				<a name="method-i-create_entity"></a>

				<div class="method-heading">
				
					<span class="method-callseq">create_entity(name, type, external_id, system_id, content)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a new entity named <tt>name</tt>.
</p>
<p>
<tt>type</tt> is an integer representing the type of entity to be created,
and it defaults to Nokogiri::XML::EntityDecl::INTERNAL_GENERAL.  See the
constants on <a href="EntityDecl.html">Nokogiri::XML::EntityDecl</a> for
more information.
</p>
<p>
<tt>external_id</tt>, <tt>system_id</tt>, and <tt>content</tt> set the
External ID, System ID, and content respectively.  All of these parameters
are optional.
</p>
					

					
					<div class="method-source-code"
						id="create-entity-source">
<pre>
static VALUE create_entity(int argc, VALUE *argv, VALUE self)
{
  VALUE name;
  VALUE type;
  VALUE external_id;
  VALUE system_id;
  VALUE content;
  xmlEntityPtr ptr;
  xmlDocPtr doc ;

  Data_Get_Struct(self, xmlDoc, doc);

  rb_scan_args(argc, argv, &quot;14&quot;, &amp;name, &amp;type, &amp;external_id, &amp;system_id,
      &amp;content);

  xmlResetLastError();
  ptr = xmlAddDocEntity(
      doc,
      (xmlChar *)(NIL_P(name)        ? NULL                        : StringValuePtr(name)),
      (int)      (NIL_P(type)        ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
      (xmlChar *)(NIL_P(external_id) ? NULL                        : StringValuePtr(external_id)),
      (xmlChar *)(NIL_P(system_id)   ? NULL                        : StringValuePtr(system_id)),
      (xmlChar *)(NIL_P(content)     ? NULL                        : StringValuePtr(content))
    );

  if(NULL == ptr) {
    xmlErrorPtr error = xmlGetLastError();
    if(error)
      rb_exc_raise(Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error));
    else
      rb_raise(rb_eRuntimeError, &quot;Could not create entity&quot;);

    return Qnil;
  }

  return Nokogiri_wrap_xml_node(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="create-text-node-method" class="method-detail ">
				<a name="method-i-create_text_node"></a>

				<div class="method-heading">
				
					<span class="method-name">create_text_node</span><span
						class="method-args">(text, &block)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a text node with <tt>text</tt>
</p>
					

					
					<div class="method-source-code"
						id="create-text-node-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 75</span>
75:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_text_node</span> <span class="ruby-identifier">text</span>, &amp;<span class="ruby-identifier">block</span>
76:         <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Text</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">text</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-keyword kw">self</span>, &amp;<span class="ruby-identifier">block</span>)
77:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="decorate-method" class="method-detail ">
				<a name="method-i-decorate"></a>

				<div class="method-heading">
				
					<span class="method-name">decorate</span><span
						class="method-args">(node)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Apply any decorators to <tt>node</tt>
</p>
					

					
					<div class="method-source-code"
						id="decorate-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 170</span>
170:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decorate</span> <span class="ruby-identifier">node</span>
171:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@decorators</span>
172:         <span class="ruby-ivar">@decorators</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">klass</span>,<span class="ruby-identifier">list</span><span class="ruby-operator">|</span>
173:           <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-identifier">klass</span>)
174:           <span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">moodule</span><span class="ruby-operator">|</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-identifier">moodule</span>) }
175:         }
176:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="decorators-method" class="method-detail ">
				<a name="method-i-decorators"></a>

				<div class="method-heading">
				
					<span class="method-name">decorators</span><span
						class="method-args">(key)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the list of decorators given <tt>key</tt>
</p>
					

					
					<div class="method-source-code"
						id="decorators-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 130</span>
130:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decorators</span> <span class="ruby-identifier">key</span>
131:         <span class="ruby-ivar">@decorators</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
132:         <span class="ruby-ivar">@decorators</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">||=</span> []
133:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="document-method" class="method-detail ">
				<a name="method-i-document"></a>

				<div class="method-heading">
				
					<span class="method-name">document</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
A reference to <tt>self</tt>
</p>
					

					
					<div class="method-source-code"
						id="document-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 90</span>
90:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">document</span>
91:         <span class="ruby-keyword kw">self</span>
92:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="dup-method" class="method-detail ">
				<a name="method-i-dup"></a>

				<div class="method-heading">
				
					<span class="method-callseq">dup</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Copy this <a href="Document.html">Document</a>.  An optional depth may be
passed in, but it defaults to a deep copy.  0 is a shallow copy, 1 is a
deep copy.
</p>
					

					
					<div class="method-source-code"
						id="dup-source">
<pre>
static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
{
  xmlDocPtr doc, dup;
  VALUE level;

  if(rb_scan_args(argc, argv, &quot;01&quot;, &amp;level) == 0)
    level = INT2NUM((long)1);

  Data_Get_Struct(self, xmlDoc, doc);

  dup = xmlCopyDoc(doc, (int)NUM2INT(level));
  if(dup == NULL) return Qnil;

  dup-&gt;type = doc-&gt;type;
  return Nokogiri_wrap_xml_document(rb_obj_class(self), dup);
}</pre>
					</div>
					
				</div>

				
				<div class="aliases">
					Also aliased as: <a href="Document.html#method-i-clone">clone</a>
				</div>
				

				
			</div>

		
			<div id="encoding-method" class="method-detail ">
				<a name="method-i-encoding"></a>

				<div class="method-heading">
				
					<span class="method-callseq">encoding</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the encoding for this <a href="Document.html">Document</a>
</p>
					

					
					<div class="method-source-code"
						id="encoding-source">
<pre>
static VALUE encoding(VALUE self)
{
  xmlDocPtr doc;
  Data_Get_Struct(self, xmlDoc, doc);

  if(!doc-&gt;encoding) return Qnil;
  return NOKOGIRI_STR_NEW2(doc-&gt;encoding);
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="encoding--method" class="method-detail ">
				<a name="method-i-encoding%3D"></a>

				<div class="method-heading">
				
					<span class="method-callseq">encoding= encoding</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Set the encoding string for this <a href="Document.html">Document</a>
</p>
					

					
					<div class="method-source-code"
						id="encoding--source">
<pre>
static VALUE set_encoding(VALUE self, VALUE encoding)
{
  xmlDocPtr doc;
  Data_Get_Struct(self, xmlDoc, doc);

  doc-&gt;encoding = xmlStrdup((xmlChar *)StringValuePtr(encoding));

  return encoding;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="fragment-method" class="method-detail ">
				<a name="method-i-fragment"></a>

				<div class="method-heading">
				
					<span class="method-name">fragment</span><span
						class="method-args">(tags = nil)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Create a <a
href="DocumentFragment.html">Nokogiri::XML::DocumentFragment</a> from
<tt>tags</tt> Returns an empty fragment if <tt>tags</tt> is nil.
</p>
					

					
					<div class="method-source-code"
						id="fragment-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 189</span>
189:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fragment</span> <span class="ruby-identifier">tags</span> = <span class="ruby-keyword kw">nil</span>
190:         <span class="ruby-constant">DocumentFragment</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">tags</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">root</span>)
191:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="name-method" class="method-detail ">
				<a name="method-i-name"></a>

				<div class="method-heading">
				
					<span class="method-name">name</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
The name of this document.  Always returns &#8220;document&#8220;
</p>
					

					
					<div class="method-source-code"
						id="name-source">
<pre>
    <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 85</span>
85:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">name</span>
86:         <span class="ruby-value str">'document'</span>
87:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="namespaces-method" class="method-detail ">
				<a name="method-i-namespaces"></a>

				<div class="method-heading">
				
					<span class="method-name">namespaces</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the hash of namespaces on the root <a
href="Node.html">Nokogiri::XML::Node</a>
</p>
					

					
					<div class="method-source-code"
						id="namespaces-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 182</span>
182:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">namespaces</span>
183:         <span class="ruby-identifier">root</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">namespaces</span> <span class="ruby-operator">:</span> {}
184:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="remove-namespaces--method" class="method-detail ">
				<a name="method-i-remove_namespaces%21"></a>

				<div class="method-heading">
				
					<span class="method-callseq">remove_namespaces!</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Remove all namespaces from all nodes in the document.
</p>
<p>
This could be useful for developers who either don&#8217;t understand
namespaces or don&#8217;t care about them.
</p>
<p>
The following example shows a use case, and you can decide for yourself
whether this is a good thing or not:
</p>
<pre>
  doc = Nokogiri::XML &lt;&lt;-EOXML
     &lt;root&gt;
       &lt;car xmlns:part=&quot;http://general-motors.com/&quot;&gt;
         &lt;part:tire&gt;Michelin Model XGV&lt;/part:tire&gt;
       &lt;/car&gt;
       &lt;bicycle xmlns:part=&quot;http://schwinn.com/&quot;&gt;
         &lt;part:tire&gt;I'm a bicycle tire!&lt;/part:tire&gt;
       &lt;/bicycle&gt;
     &lt;/root&gt;
     EOXML
  
  doc.xpath(&quot;//tire&quot;).to_s # =&gt; &quot;&quot;
  doc.xpath(&quot;//part:tire&quot;, &quot;part&quot; =&gt; &quot;http://general-motors.com/&quot;).to_s # =&gt; &quot;&lt;part:tire&gt;Michelin Model XGV&lt;/part:tire&gt;&quot;
  doc.xpath(&quot;//part:tire&quot;, &quot;part&quot; =&gt; &quot;http://schwinn.com/&quot;).to_s # =&gt; &quot;&lt;part:tire&gt;I'm a bicycle tire!&lt;/part:tire&gt;&quot;
  
  doc.remove_namespaces!
  
  doc.xpath(&quot;//tire&quot;).to_s # =&gt; &quot;&lt;tire&gt;Michelin Model XGV&lt;/tire&gt;&lt;tire&gt;I'm a bicycle tire!&lt;/tire&gt;&quot;
  doc.xpath(&quot;//part:tire&quot;, &quot;part&quot; =&gt; &quot;http://general-motors.com/&quot;).to_s # =&gt; &quot;&quot;
  doc.xpath(&quot;//part:tire&quot;, &quot;part&quot; =&gt; &quot;http://schwinn.com/&quot;).to_s # =&gt; &quot;&quot;
</pre>
<p>
For more information on why this probably is <b>not</b> a good thing in
general, please direct your browser to <a
href="http://tenderlovemaking.com/2009/04/23/namespaces-in-xml/">tenderlovemaking.com/2009/04/23/namespaces-in-xml/</a>
</p>
					

					
					<div class="method-source-code"
						id="remove-namespaces--source">
<pre>
VALUE remove_namespaces_bang(VALUE self)
{
  xmlDocPtr doc ;
  Data_Get_Struct(self, xmlDoc, doc);

  recursively_remove_namespaces_from_node((xmlNodePtr)doc);
  return self;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="root-method" class="method-detail ">
				<a name="method-i-root"></a>

				<div class="method-heading">
				
					<span class="method-callseq">root</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the root node for this document.
</p>
					

					
					<div class="method-source-code"
						id="root-source">
<pre>
static VALUE root(VALUE self)
{
  xmlDocPtr doc;
  xmlNodePtr root;

  Data_Get_Struct(self, xmlDoc, doc);

  root = xmlDocGetRootElement(doc);

  if(!root) return Qnil;
  return Nokogiri_wrap_xml_node(Qnil, root) ;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="root--method" class="method-detail ">
				<a name="method-i-root%3D"></a>

				<div class="method-heading">
				
					<span class="method-callseq">root=</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Set the root element on this document
</p>
					

					
					<div class="method-source-code"
						id="root--source">
<pre>
static VALUE set_root(VALUE self, VALUE root)
{
  xmlDocPtr doc;
  xmlNodePtr new_root;
  xmlNodePtr old_root;

  Data_Get_Struct(self, xmlDoc, doc);

  old_root = NULL;

  if(NIL_P(root)) {
    old_root = xmlDocGetRootElement(doc);

    if(old_root) {
      xmlUnlinkNode(old_root);
      NOKOGIRI_ROOT_NODE(old_root);
    }

    return root;
  }

  Data_Get_Struct(root, xmlNode, new_root);


  /* If the new root's document is not the same as the current document,
   * then we need to dup the node in to this document. */
  if(new_root-&gt;doc != doc) {
    old_root = xmlDocGetRootElement(doc);
    if (!(new_root = xmlDocCopyNode(new_root, doc, 1))) {
      rb_raise(rb_eRuntimeError, &quot;Could not reparent node (xmlDocCopyNode)&quot;);
    }
  }

  xmlDocSetRootElement(doc, new_root);
  if(old_root) NOKOGIRI_ROOT_NODE(old_root);
  return root;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="slop--method" class="method-detail ">
				<a name="method-i-slop%21"></a>

				<div class="method-heading">
				
					<span class="method-name">slop!</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Explore a document with shortcut methods. See Nokogiri::Slop for details.
</p>
<p>
Note that any nodes that have been instantiated before <a
href="Document.html#method-i-slop%21">#</a> is called will not be decorated
with sloppy behavior. So, if you&#8217;re in irb, the preferred idiom is:
</p>
<pre>
  irb&gt; doc = Nokogiri::Slop my_markup
</pre>
<p>
and not
</p>
<pre>
  irb&gt; doc = Nokogiri::HTML my_markup
  ... followed by irb's implicit inspect (and therefore instantiation of every node) ...
  irb&gt; doc.slop!
  ... which does absolutely nothing.</pre>
					

					
					<div class="method-source-code"
						id="slop--source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 159</span>
159:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">slop!</span>
160:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">decorators</span>(<span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>).<span class="ruby-identifier">include?</span> <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">Decorators</span><span class="ruby-operator">::</span><span class="ruby-constant">Slop</span>
161:           <span class="ruby-identifier">decorators</span>(<span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">Decorators</span><span class="ruby-operator">::</span><span class="ruby-constant">Slop</span>
162:           <span class="ruby-identifier">decorate!</span>
163:         <span class="ruby-keyword kw">end</span>
164: 
165:         <span class="ruby-keyword kw">self</span>
166:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="url-method" class="method-detail ">
				<a name="method-i-url"></a>

				<div class="method-heading">
				
					<span class="method-callseq">url</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the url name for this document.
</p>
					

					
					<div class="method-source-code"
						id="url-source">
<pre>
static VALUE url(VALUE self)
{
  xmlDocPtr doc;
  Data_Get_Struct(self, xmlDoc, doc);

  if(doc-&gt;URL) return NOKOGIRI_STR_NEW2(doc-&gt;URL);

  return Qnil;
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="validate-method" class="method-detail ">
				<a name="method-i-validate"></a>

				<div class="method-heading">
				
					<span class="method-name">validate</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Validate this <a href="Document.html">Document</a> against it&#8217;s <a
href="DTD.html">DTD</a>.  Returns a list of errors on the document or
<tt>nil</tt> when there is no <a href="DTD.html">DTD</a>.
</p>
					

					
					<div class="method-source-code"
						id="validate-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 138</span>
138:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validate</span>
139:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">internal_subset</span>
140:         <span class="ruby-identifier">internal_subset</span>.<span class="ruby-identifier">validate</span> <span class="ruby-keyword kw">self</span>
141:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="version-method" class="method-detail ">
				<a name="method-i-version"></a>

				<div class="method-heading">
				
					<span class="method-callseq">version</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Get the <a href="../XML.html">XML</a> version for this <a
href="Document.html">Document</a>
</p>
					

					
					<div class="method-source-code"
						id="version-source">
<pre>
static VALUE version(VALUE self)
{
  xmlDocPtr doc;
  Data_Get_Struct(self, xmlDoc, doc);

  if(!doc-&gt;version) return Qnil;
  return NOKOGIRI_STR_NEW2(doc-&gt;version);
}</pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="private-instance-method-details" class="method-section section">
			<h3 class="section-header">Private Instance Methods</h3>

		
			<div id="implied-xpath-context-method" class="method-detail ">
				<a name="method-i-implied_xpath_context"></a>

				<div class="method-heading">
				
					<span class="method-name">implied_xpath_context</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="implied-xpath-context-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 209</span>
209:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">implied_xpath_context</span>
210:         <span class="ruby-value str">&quot;/&quot;</span>
211:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="inspect-attributes-method" class="method-detail ">
				<a name="method-i-inspect_attributes"></a>

				<div class="method-heading">
				
					<span class="method-name">inspect_attributes</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="inspect-attributes-source">
<pre>
     <span class="ruby-comment cmt"># File lib/nokogiri/xml/document.rb, line 213</span>
213:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect_attributes</span>
214:         [<span class="ruby-value">:name</span>, <span class="ruby-value">:children</span>]
215:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

