magic_xml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/doc/classes/Array.html +148 -0
- data/doc/classes/File.html +113 -0
- data/doc/classes/Hash.html +117 -0
- data/doc/classes/Patterns_all.html +145 -0
- data/doc/classes/Patterns_any.html +145 -0
- data/doc/classes/String.html +470 -0
- data/doc/classes/Symbol.html +145 -0
- data/doc/classes/XML.html +1881 -0
- data/doc/classes/XML_Comment.html +148 -0
- data/doc/classes/XML_PI.html +145 -0
- data/doc/classes/XML_Tests.html +1727 -0
- data/doc/files/magic_xml_rb.html +186 -0
- data/doc/files/simple_examples/xml_hello_f_rb.html +88 -0
- data/doc/files/simple_examples/xml_hello_m_rb.html +88 -0
- data/doc/files/simple_examples/xml_list_f_rb.html +88 -0
- data/doc/files/simple_examples/xml_list_m_rb.html +88 -0
- data/doc/files/tests_rb.html +94 -0
- data/doc/files/xquery_use_cases/parts/q1_rb.html +117 -0
- data/doc/files/xquery_use_cases/rdb/q10_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q11_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q12_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q13_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q14_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q15_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q16_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q17_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q18_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q6_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q7_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q8_rb.html +88 -0
- data/doc/files/xquery_use_cases/rdb/q9_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/seq/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q10_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q6_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q7_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q8a_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q8b_rb.html +88 -0
- data/doc/files/xquery_use_cases/sgml/q9_rb.html +88 -0
- data/doc/files/xquery_use_cases/solution_sizes_rb.html +88 -0
- data/doc/files/xquery_use_cases/string/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/string/q2_rb.html +93 -0
- data/doc/files/xquery_use_cases/string/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/string/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/test_driver_rb.html +92 -0
- data/doc/files/xquery_use_cases/tree/q1_rb.html +111 -0
- data/doc/files/xquery_use_cases/tree/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q5_rb.html +88 -0
- data/doc/files/xquery_use_cases/tree/q6_rb.html +113 -0
- data/doc/files/xquery_use_cases/xmp/q10_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q11_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q12_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q1_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q2_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q3_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q4_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q5_rb.html +92 -0
- data/doc/files/xquery_use_cases/xmp/q6_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q7_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q8_rb.html +88 -0
- data/doc/files/xquery_use_cases/xmp/q9_rb.html +88 -0
- data/doc/fr_class_index.html +56 -0
- data/doc/fr_file_index.html +110 -0
- data/doc/fr_method_index.html +159 -0
- data/doc/index.html +26 -0
- data/doc/rdoc-style.css +175 -0
- data/lib/magic_xml.rb +1400 -0
- data/simple_examples/README +14 -0
- data/simple_examples/xml_hello_f.rb +32 -0
- data/simple_examples/xml_hello_m.rb +32 -0
- data/simple_examples/xml_list_f.rb +36 -0
- data/simple_examples/xml_list_m.rb +36 -0
- data/test/helper.rb +9 -0
- data/test/test_magic_xml.rb +855 -0
- data/xquery_use_cases/README +17 -0
- data/xquery_use_cases/parts/README +12 -0
- data/xquery_use_cases/parts/partlist.xml +13 -0
- data/xquery_use_cases/parts/q1.out +16 -0
- data/xquery_use_cases/parts/q1.rb +38 -0
- data/xquery_use_cases/parts/q1.xquery +18 -0
- data/xquery_use_cases/rdb/README +50 -0
- data/xquery_use_cases/rdb/bids.xml +81 -0
- data/xquery_use_cases/rdb/items.xml +57 -0
- data/xquery_use_cases/rdb/q1.out +10 -0
- data/xquery_use_cases/rdb/q1.rb +31 -0
- data/xquery_use_cases/rdb/q1.xquery +14 -0
- data/xquery_use_cases/rdb/q10.out +27 -0
- data/xquery_use_cases/rdb/q10.rb +37 -0
- data/xquery_use_cases/rdb/q10.xquery +15 -0
- data/xquery_use_cases/rdb/q11.out +7 -0
- data/xquery_use_cases/rdb/q11.rb +38 -0
- data/xquery_use_cases/rdb/q11.xquery +15 -0
- data/xquery_use_cases/rdb/q12.out +12 -0
- data/xquery_use_cases/rdb/q12.rb +42 -0
- data/xquery_use_cases/rdb/q12.xquery +28 -0
- data/xquery_use_cases/rdb/q13.out +32 -0
- data/xquery_use_cases/rdb/q13.rb +45 -0
- data/xquery_use_cases/rdb/q13.xquery +15 -0
- data/xquery_use_cases/rdb/q14.out +14 -0
- data/xquery_use_cases/rdb/q14.rb +42 -0
- data/xquery_use_cases/rdb/q14.xquery +14 -0
- data/xquery_use_cases/rdb/q15.out +5 -0
- data/xquery_use_cases/rdb/q15.rb +31 -0
- data/xquery_use_cases/rdb/q15.xquery +9 -0
- data/xquery_use_cases/rdb/q16.out +35 -0
- data/xquery_use_cases/rdb/q16.rb +35 -0
- data/xquery_use_cases/rdb/q16.xquery +17 -0
- data/xquery_use_cases/rdb/q17.out +1 -0
- data/xquery_use_cases/rdb/q17.rb +35 -0
- data/xquery_use_cases/rdb/q17.xquery +11 -0
- data/xquery_use_cases/rdb/q18.out +32 -0
- data/xquery_use_cases/rdb/q18.rb +40 -0
- data/xquery_use_cases/rdb/q18.xquery +19 -0
- data/xquery_use_cases/rdb/q2.out +22 -0
- data/xquery_use_cases/rdb/q2.rb +36 -0
- data/xquery_use_cases/rdb/q2.xquery +14 -0
- data/xquery_use_cases/rdb/q3.out +8 -0
- data/xquery_use_cases/rdb/q3.rb +34 -0
- data/xquery_use_cases/rdb/q3.xquery +16 -0
- data/xquery_use_cases/rdb/q4.out +14 -0
- data/xquery_use_cases/rdb/q4.rb +31 -0
- data/xquery_use_cases/rdb/q4.xquery +11 -0
- data/xquery_use_cases/rdb/q5.out +12 -0
- data/xquery_use_cases/rdb/q5.rb +46 -0
- data/xquery_use_cases/rdb/q5.xquery +25 -0
- data/xquery_use_cases/rdb/q6.out +14 -0
- data/xquery_use_cases/rdb/q6.rb +38 -0
- data/xquery_use_cases/rdb/q6.xquery +15 -0
- data/xquery_use_cases/rdb/q7.out +1 -0
- data/xquery_use_cases/rdb/q7.rb +30 -0
- data/xquery_use_cases/rdb/q7.xquery +10 -0
- data/xquery_use_cases/rdb/q8.out +1 -0
- data/xquery_use_cases/rdb/q8.rb +23 -0
- data/xquery_use_cases/rdb/q8.xquery +8 -0
- data/xquery_use_cases/rdb/q9.out +22 -0
- data/xquery_use_cases/rdb/q9.rb +32 -0
- data/xquery_use_cases/rdb/q9.xquery +16 -0
- data/xquery_use_cases/rdb/users.xml +25 -0
- data/xquery_use_cases/seq/README +12 -0
- data/xquery_use_cases/seq/q1.out +1 -0
- data/xquery_use_cases/seq/q1.rb +25 -0
- data/xquery_use_cases/seq/q1.xquery +2 -0
- data/xquery_use_cases/seq/q2.out +2 -0
- data/xquery_use_cases/seq/q2.rb +25 -0
- data/xquery_use_cases/seq/q2.xquery +2 -0
- data/xquery_use_cases/seq/q3.out +2 -0
- data/xquery_use_cases/seq/q3.rb +26 -0
- data/xquery_use_cases/seq/q3.xquery +3 -0
- data/xquery_use_cases/seq/q4.out +0 -0
- data/xquery_use_cases/seq/q4.rb +27 -0
- data/xquery_use_cases/seq/q4.xquery +4 -0
- data/xquery_use_cases/seq/q5.out +5 -0
- data/xquery_use_cases/seq/q5.rb +29 -0
- data/xquery_use_cases/seq/q5.xquery +10 -0
- data/xquery_use_cases/seq/report1.xml +40 -0
- data/xquery_use_cases/sgml/README +53 -0
- data/xquery_use_cases/sgml/q1.out +44 -0
- data/xquery_use_cases/sgml/q1.rb +23 -0
- data/xquery_use_cases/sgml/q1.xquery +5 -0
- data/xquery_use_cases/sgml/q10.out +1 -0
- data/xquery_use_cases/sgml/q10.rb +28 -0
- data/xquery_use_cases/sgml/q10.xquery +7 -0
- data/xquery_use_cases/sgml/q2.out +26 -0
- data/xquery_use_cases/sgml/q2.rb +23 -0
- data/xquery_use_cases/sgml/q2.xquery +5 -0
- data/xquery_use_cases/sgml/q3.out +6 -0
- data/xquery_use_cases/sgml/q3.rb +28 -0
- data/xquery_use_cases/sgml/q3.xquery +7 -0
- data/xquery_use_cases/sgml/q4.out +4 -0
- data/xquery_use_cases/sgml/q4.rb +25 -0
- data/xquery_use_cases/sgml/q4.xquery +5 -0
- data/xquery_use_cases/sgml/q5.out +3 -0
- data/xquery_use_cases/sgml/q5.rb +23 -0
- data/xquery_use_cases/sgml/q5.xquery +5 -0
- data/xquery_use_cases/sgml/q6.out +1 -0
- data/xquery_use_cases/sgml/q6.rb +27 -0
- data/xquery_use_cases/sgml/q6.xquery +6 -0
- data/xquery_use_cases/sgml/q7.out +1 -0
- data/xquery_use_cases/sgml/q7.rb +27 -0
- data/xquery_use_cases/sgml/q7.xquery +7 -0
- data/xquery_use_cases/sgml/q8a.out +34 -0
- data/xquery_use_cases/sgml/q8a.rb +27 -0
- data/xquery_use_cases/sgml/q8a.xquery +5 -0
- data/xquery_use_cases/sgml/q8b.out +26 -0
- data/xquery_use_cases/sgml/q8b.rb +32 -0
- data/xquery_use_cases/sgml/q8b.xquery +5 -0
- data/xquery_use_cases/sgml/q9.out +9 -0
- data/xquery_use_cases/sgml/q9.rb +29 -0
- data/xquery_use_cases/sgml/q9.xquery +6 -0
- data/xquery_use_cases/sgml/sgml.xml +101 -0
- data/xquery_use_cases/solution_sizes.rb +48 -0
- data/xquery_use_cases/string/README +29 -0
- data/xquery_use_cases/string/company-data.xml +20 -0
- data/xquery_use_cases/string/q1.out +4 -0
- data/xquery_use_cases/string/q1.rb +25 -0
- data/xquery_use_cases/string/q1.xquery +1 -0
- data/xquery_use_cases/string/q2.out +13 -0
- data/xquery_use_cases/string/q2.rb +32 -0
- data/xquery_use_cases/string/q2.xquery +23 -0
- data/xquery_use_cases/string/q4.out +50 -0
- data/xquery_use_cases/string/q4.rb +34 -0
- data/xquery_use_cases/string/q4.xquery +14 -0
- data/xquery_use_cases/string/q5.out +12 -0
- data/xquery_use_cases/string/q5.rb +33 -0
- data/xquery_use_cases/string/q5.xquery +8 -0
- data/xquery_use_cases/string/string.xml +82 -0
- data/xquery_use_cases/test_driver.rb +60 -0
- data/xquery_use_cases/tree/README +23 -0
- data/xquery_use_cases/tree/book.xml +50 -0
- data/xquery_use_cases/tree/q1.out +23 -0
- data/xquery_use_cases/tree/q1.rb +31 -0
- data/xquery_use_cases/tree/q1.xquery +14 -0
- data/xquery_use_cases/tree/q2.out +11 -0
- data/xquery_use_cases/tree/q2.rb +27 -0
- data/xquery_use_cases/tree/q2.xquery +10 -0
- data/xquery_use_cases/tree/q3.out +2 -0
- data/xquery_use_cases/tree/q3.rb +26 -0
- data/xquery_use_cases/tree/q3.xquery +2 -0
- data/xquery_use_cases/tree/q4.out +1 -0
- data/xquery_use_cases/tree/q4.rb +23 -0
- data/xquery_use_cases/tree/q4.xquery +5 -0
- data/xquery_use_cases/tree/q5.out +9 -0
- data/xquery_use_cases/tree/q5.rb +30 -0
- data/xquery_use_cases/tree/q5.xquery +8 -0
- data/xquery_use_cases/tree/q6.out +30 -0
- data/xquery_use_cases/tree/q6.rb +35 -0
- data/xquery_use_cases/tree/q6.xquery +21 -0
- data/xquery_use_cases/xmp/README +41 -0
- data/xquery_use_cases/xmp/bib.xml +35 -0
- data/xquery_use_cases/xmp/books.xml +15 -0
- data/xquery_use_cases/xmp/prices.xml +32 -0
- data/xquery_use_cases/xmp/q1.out +8 -0
- data/xquery_use_cases/xmp/q1.rb +29 -0
- data/xquery_use_cases/xmp/q1.xquery +10 -0
- data/xquery_use_cases/xmp/q10.out +11 -0
- data/xquery_use_cases/xmp/q10.rb +36 -0
- data/xquery_use_cases/xmp/q10.xquery +11 -0
- data/xquery_use_cases/xmp/q11.out +35 -0
- data/xquery_use_cases/xmp/q11.rb +37 -0
- data/xquery_use_cases/xmp/q11.xquery +18 -0
- data/xquery_use_cases/xmp/q12.out +6 -0
- data/xquery_use_cases/xmp/q12.rb +35 -0
- data/xquery_use_cases/xmp/q12.xquery +20 -0
- data/xquery_use_cases/xmp/q2.out +37 -0
- data/xquery_use_cases/xmp/q2.rb +30 -0
- data/xquery_use_cases/xmp/q2.xquery +12 -0
- data/xquery_use_cases/xmp/q3.out +34 -0
- data/xquery_use_cases/xmp/q3.rb +27 -0
- data/xquery_use_cases/xmp/q3.xquery +10 -0
- data/xquery_use_cases/xmp/q4.out +31 -0
- data/xquery_use_cases/xmp/q4.rb +44 -0
- data/xquery_use_cases/xmp/q4.xquery +21 -0
- data/xquery_use_cases/xmp/q5.out +17 -0
- data/xquery_use_cases/xmp/q5.rb +38 -0
- data/xquery_use_cases/xmp/q5.xquery +13 -0
- data/xquery_use_cases/xmp/q6.out +28 -0
- data/xquery_use_cases/xmp/q6.rb +33 -0
- data/xquery_use_cases/xmp/q6.xquery +19 -0
- data/xquery_use_cases/xmp/q7.out +8 -0
- data/xquery_use_cases/xmp/q7.rb +30 -0
- data/xquery_use_cases/xmp/q7.xquery +12 -0
- data/xquery_use_cases/xmp/q8.out +7 -0
- data/xquery_use_cases/xmp/q8.rb +29 -0
- data/xquery_use_cases/xmp/q8.xquery +9 -0
- data/xquery_use_cases/xmp/q9.out +4 -0
- data/xquery_use_cases/xmp/q9.rb +29 -0
- data/xquery_use_cases/xmp/q9.xquery +7 -0
- data/xquery_use_cases/xmp/reviews.xml +24 -0
- metadata +342 -0
@@ -0,0 +1,1881 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
<html>
|
6
|
+
<head>
|
7
|
+
<title>Class: XML</title>
|
8
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
9
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
<script language="JavaScript" type="text/javascript">
|
12
|
+
// <![CDATA[
|
13
|
+
|
14
|
+
function toggleSource( id )
|
15
|
+
{
|
16
|
+
var elem
|
17
|
+
var link
|
18
|
+
|
19
|
+
if( document.getElementById )
|
20
|
+
{
|
21
|
+
elem = document.getElementById( id )
|
22
|
+
link = document.getElementById( "l_" + id )
|
23
|
+
}
|
24
|
+
else if ( document.all )
|
25
|
+
{
|
26
|
+
elem = eval( "document.all." + id )
|
27
|
+
link = eval( "document.all.l_" + id )
|
28
|
+
}
|
29
|
+
else
|
30
|
+
return false;
|
31
|
+
|
32
|
+
if( elem.style.display == "block" )
|
33
|
+
{
|
34
|
+
elem.style.display = "none"
|
35
|
+
link.innerHTML = "show source"
|
36
|
+
}
|
37
|
+
else
|
38
|
+
{
|
39
|
+
elem.style.display = "block"
|
40
|
+
link.innerHTML = "hide source"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
function openCode( url )
|
45
|
+
{
|
46
|
+
window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
|
47
|
+
}
|
48
|
+
// ]]>
|
49
|
+
</script>
|
50
|
+
</head>
|
51
|
+
|
52
|
+
<body>
|
53
|
+
<table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
|
54
|
+
<td class="file-title"><span class="file-title-prefix">Class</span><br />XML</td>
|
55
|
+
<td align="right">
|
56
|
+
<table cellspacing=0 cellpadding=2>
|
57
|
+
<tr valign="top">
|
58
|
+
<td>In:</td>
|
59
|
+
<td>
|
60
|
+
<a href="../files/magic_xml_rb.html">magic_xml.rb</a>
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<td>Parent:</td>
|
65
|
+
<td>
|
66
|
+
Object
|
67
|
+
</td>
|
68
|
+
</tr>
|
69
|
+
</table>
|
70
|
+
</td>
|
71
|
+
</tr>
|
72
|
+
</table>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
<div id="content">
|
77
|
+
|
78
|
+
<div class="description"><p>
|
79
|
+
Instance methods (other than those of Enumerable)
|
80
|
+
</p>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<div class="sectiontitle">Methods</div>
|
86
|
+
<ul>
|
87
|
+
<li><a href="#M000031"><<</a></li>
|
88
|
+
<li><a href="#M000032">==</a></li>
|
89
|
+
<li><a href="#M000037">=~</a></li>
|
90
|
+
<li><a href="#M000029">[]</a></li>
|
91
|
+
<li><a href="#M000030">[]=</a></li>
|
92
|
+
<li><a href="#M000045">add!</a></li>
|
93
|
+
<li><a href="#M000040">add_pretty_printing!</a></li>
|
94
|
+
<li><a href="#M000048">child</a></li>
|
95
|
+
<li><a href="#M000050">children</a></li>
|
96
|
+
<li><a href="#M000014">children_sort_by</a></li>
|
97
|
+
<li><a href="#M000052">deep_map</a></li>
|
98
|
+
<li><a href="#M000049">descendant</a></li>
|
99
|
+
<li><a href="#M000051">descendants</a></li>
|
100
|
+
<li><a href="#M000042">dup</a></li>
|
101
|
+
<li><a href="#M000012">each</a></li>
|
102
|
+
<li><a href="#M000034">exec!</a></li>
|
103
|
+
<li><a href="#M000017">from_file</a></li>
|
104
|
+
<li><a href="#M000018">from_url</a></li>
|
105
|
+
<li><a href="#M000028">inspect</a></li>
|
106
|
+
<li><a href="#M000019">load</a></li>
|
107
|
+
<li><a href="#M000053">map</a></li>
|
108
|
+
<li><a href="#M000033">method_missing</a></li>
|
109
|
+
<li><a href="#M000016">method_missing</a></li>
|
110
|
+
<li><a href="#M000026">new</a></li>
|
111
|
+
<li><a href="#M000046">normalize!</a></li>
|
112
|
+
<li><a href="#M000022">parse</a></li>
|
113
|
+
<li><a href="#M000020">parse_as_twigs</a></li>
|
114
|
+
<li><a href="#M000023">parse_sequence</a></li>
|
115
|
+
<li><a href="#M000021">parse_subtree</a></li>
|
116
|
+
<li><a href="#M000035">range</a></li>
|
117
|
+
<li><a href="#M000041">real_add_pretty_printing!</a></li>
|
118
|
+
<li><a href="#M000039">real_remove_pretty_printing!</a></li>
|
119
|
+
<li><a href="#M000038">remove_pretty_printing!</a></li>
|
120
|
+
<li><a href="#M000024">renormalize</a></li>
|
121
|
+
<li><a href="#M000025">renormalize_sequence</a></li>
|
122
|
+
<li><a href="#M000015">sort</a></li>
|
123
|
+
<li><a href="#M000013">sort_by</a></li>
|
124
|
+
<li><a href="#M000036">subsequence</a></li>
|
125
|
+
<li><a href="#M000047">text</a></li>
|
126
|
+
<li><a href="#M000043">text!</a></li>
|
127
|
+
<li><a href="#M000027">to_s</a></li>
|
128
|
+
<li><a href="#M000044">xml!</a></li>
|
129
|
+
</ul>
|
130
|
+
|
131
|
+
<div class="sectiontitle">Included Modules</div>
|
132
|
+
<ul>
|
133
|
+
<li>Enumerable</li>
|
134
|
+
</ul>
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
<div class="sectiontitle">Attributes</div>
|
140
|
+
<table border='0' cellpadding='5'>
|
141
|
+
<tr valign='top'>
|
142
|
+
<td class='attr-rw'>
|
143
|
+
[RW]
|
144
|
+
</td>
|
145
|
+
<td class='attr-name'>attrs</td>
|
146
|
+
<td class='attr-desc'></td>
|
147
|
+
</tr>
|
148
|
+
<tr valign='top'>
|
149
|
+
<td class='attr-rw'>
|
150
|
+
[RW]
|
151
|
+
</td>
|
152
|
+
<td class='attr-name'>contents</td>
|
153
|
+
<td class='attr-desc'></td>
|
154
|
+
</tr>
|
155
|
+
<tr valign='top'>
|
156
|
+
<td class='attr-rw'>
|
157
|
+
[RW]
|
158
|
+
</td>
|
159
|
+
<td class='attr-name'>name</td>
|
160
|
+
<td class='attr-desc'></td>
|
161
|
+
</tr>
|
162
|
+
</table>
|
163
|
+
|
164
|
+
<div class="sectiontitle">Public Class methods</div>
|
165
|
+
<div class="method">
|
166
|
+
<div class="title">
|
167
|
+
<a name="M000017"></a><b>from_file</b>(file)
|
168
|
+
</div>
|
169
|
+
<div class="description">
|
170
|
+
<p>
|
171
|
+
Read file and <a href="XML.html#M000022">parse</a>
|
172
|
+
</p>
|
173
|
+
</div>
|
174
|
+
<div class="sourcecode">
|
175
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000017_source')" id="l_M000017_source">show source</a> ]</p>
|
176
|
+
<div id="M000017_source" class="dyn-source">
|
177
|
+
<pre>
|
178
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 442</span>
|
179
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">from_file</span>(<span class="ruby-identifier">file</span>)
|
180
|
+
<span class="ruby-identifier">file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
181
|
+
<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">file</span>)
|
182
|
+
<span class="ruby-keyword kw">end</span>
|
183
|
+
</pre>
|
184
|
+
</div>
|
185
|
+
</div>
|
186
|
+
</div>
|
187
|
+
<div class="method">
|
188
|
+
<div class="title">
|
189
|
+
<a name="M000018"></a><b>from_url</b>(url)
|
190
|
+
</div>
|
191
|
+
<div class="description">
|
192
|
+
<p>
|
193
|
+
Fetch URL and <a href="XML.html#M000022">parse</a> Supported:
|
194
|
+
http://…/ https://…/ file:foo.xml string:<foo/>
|
195
|
+
</p>
|
196
|
+
</div>
|
197
|
+
<div class="sourcecode">
|
198
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000018_source')" id="l_M000018_source">show source</a> ]</p>
|
199
|
+
<div id="M000018_source" class="dyn-source">
|
200
|
+
<pre>
|
201
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 453</span>
|
202
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">from_url</span>(<span class="ruby-identifier">url</span>)
|
203
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^string:(.*)$/</span><span class="ruby-identifier">m</span>
|
204
|
+
<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">$1</span>)
|
205
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">url</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^file:(.*)$/</span><span class="ruby-identifier">m</span>
|
206
|
+
<span class="ruby-identifier">from_file</span>(<span class="ruby-identifier">$1</span>)
|
207
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">url</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^http(s?):/</span>
|
208
|
+
<span class="ruby-identifier">ssl</span> = (<span class="ruby-identifier">$1</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"s"</span>)
|
209
|
+
<span class="ruby-comment cmt"># No, seriously - Ruby needs something better than net/http</span>
|
210
|
+
<span class="ruby-comment cmt"># Something that groks basic auth and queries and redirects automatically:</span>
|
211
|
+
<span class="ruby-comment cmt"># HTTP_LIBRARY.get_content("http://username:passwd/u.r.l/?query")</span>
|
212
|
+
<span class="ruby-comment cmt"># URI parsing must go inside the library, client programs</span>
|
213
|
+
<span class="ruby-comment cmt"># should have nothing to do with it</span>
|
214
|
+
|
215
|
+
<span class="ruby-comment cmt"># net/http is really inconvenient to use here</span>
|
216
|
+
<span class="ruby-identifier">u</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">url</span>)
|
217
|
+
<span class="ruby-comment cmt"># You're not seeing this:</span>
|
218
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">query</span> <span class="ruby-keyword kw">then</span>
|
219
|
+
<span class="ruby-identifier">path</span> = <span class="ruby-identifier">u</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"?"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">query</span>
|
220
|
+
<span class="ruby-keyword kw">else</span>
|
221
|
+
<span class="ruby-identifier">path</span> = <span class="ruby-identifier">u</span>.<span class="ruby-identifier">path</span>
|
222
|
+
<span class="ruby-keyword kw">end</span>
|
223
|
+
<span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>)
|
224
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">userinfo</span>
|
225
|
+
<span class="ruby-identifier">username</span>, <span class="ruby-identifier">passwd</span> = <span class="ruby-identifier">u</span>.<span class="ruby-identifier">userinfo</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/:/</span>,<span class="ruby-value">2</span>)
|
226
|
+
<span class="ruby-identifier">req</span>.<span class="ruby-identifier">basic_auth</span> <span class="ruby-identifier">username</span>, <span class="ruby-identifier">passwd</span>
|
227
|
+
<span class="ruby-keyword kw">end</span>
|
228
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ssl</span>
|
229
|
+
<span class="ruby-comment cmt"># NOTE: You need libopenssl-ruby installed</span>
|
230
|
+
<span class="ruby-comment cmt"># if you want to use HTTPS. Ubuntu is broken</span>
|
231
|
+
<span class="ruby-comment cmt"># as it doesn't provide it in the default packages.</span>
|
232
|
+
<span class="ruby-identifier">require</span> <span class="ruby-value str">'net/https'</span>
|
233
|
+
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">u</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">u</span>.<span class="ruby-identifier">port</span>)
|
234
|
+
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword kw">true</span>
|
235
|
+
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">verify_mode</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_NONE</span>
|
236
|
+
<span class="ruby-keyword kw">else</span>
|
237
|
+
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">u</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">u</span>.<span class="ruby-identifier">port</span>)
|
238
|
+
<span class="ruby-keyword kw">end</span>
|
239
|
+
|
240
|
+
<span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>) }
|
241
|
+
<span class="ruby-comment cmt"># TODO: Throw a more meaningful exception</span>
|
242
|
+
<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>)
|
243
|
+
<span class="ruby-keyword kw">else</span>
|
244
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"URL protocol #{url} not supported (http, https, file, string are supported)"</span>
|
245
|
+
<span class="ruby-keyword kw">end</span>
|
246
|
+
<span class="ruby-keyword kw">end</span>
|
247
|
+
</pre>
|
248
|
+
</div>
|
249
|
+
</div>
|
250
|
+
</div>
|
251
|
+
<div class="method">
|
252
|
+
<div class="title">
|
253
|
+
<a name="M000019"></a><b>load</b>(obj)
|
254
|
+
</div>
|
255
|
+
<div class="description">
|
256
|
+
<p>
|
257
|
+
Like CDuce load_xml The path can be:
|
258
|
+
</p>
|
259
|
+
<ul>
|
260
|
+
<li>file handler
|
261
|
+
|
262
|
+
</li>
|
263
|
+
<li>URL (a string with :)
|
264
|
+
|
265
|
+
</li>
|
266
|
+
<li>file name (a string without :)
|
267
|
+
|
268
|
+
</li>
|
269
|
+
</ul>
|
270
|
+
</div>
|
271
|
+
<div class="sourcecode">
|
272
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000019_source')" id="l_M000019_source">show source</a> ]</p>
|
273
|
+
<div id="M000019_source" class="dyn-source">
|
274
|
+
<pre>
|
275
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 504</span>
|
276
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">obj</span>)
|
277
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
278
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">":"</span>
|
279
|
+
<span class="ruby-identifier">from_url</span>(<span class="ruby-identifier">obj</span>)
|
280
|
+
<span class="ruby-keyword kw">else</span>
|
281
|
+
<span class="ruby-identifier">from_file</span>(<span class="ruby-identifier">obj</span>)
|
282
|
+
<span class="ruby-keyword kw">end</span>
|
283
|
+
<span class="ruby-keyword kw">else</span>
|
284
|
+
<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">obj</span>)
|
285
|
+
<span class="ruby-keyword kw">end</span>
|
286
|
+
<span class="ruby-keyword kw">end</span>
|
287
|
+
</pre>
|
288
|
+
</div>
|
289
|
+
</div>
|
290
|
+
</div>
|
291
|
+
<div class="method">
|
292
|
+
<div class="title">
|
293
|
+
<a name="M000016"></a><b>method_missing</b>(meth, *args, &blk)
|
294
|
+
</div>
|
295
|
+
<div class="description">
|
296
|
+
<p>
|
297
|
+
XML.foo! == <a href="XML.html#M000044">xml!</a>(:foo) XML.foo == xml(:foo)
|
298
|
+
</p>
|
299
|
+
</div>
|
300
|
+
<div class="sourcecode">
|
301
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000016_source')" id="l_M000016_source">show source</a> ]</p>
|
302
|
+
<div id="M000016_source" class="dyn-source">
|
303
|
+
<pre>
|
304
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 433</span>
|
305
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">meth</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
306
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">meth</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^(.*)!$/</span>
|
307
|
+
<span class="ruby-identifier">xml!</span>(<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
308
|
+
<span class="ruby-keyword kw">else</span>
|
309
|
+
<span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">meth</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
310
|
+
<span class="ruby-keyword kw">end</span>
|
311
|
+
<span class="ruby-keyword kw">end</span>
|
312
|
+
</pre>
|
313
|
+
</div>
|
314
|
+
</div>
|
315
|
+
</div>
|
316
|
+
<div class="method">
|
317
|
+
<div class="title">
|
318
|
+
<a name="M000026"></a><b>new</b>(*args, &blk)
|
319
|
+
</div>
|
320
|
+
<div class="description">
|
321
|
+
<p>
|
322
|
+
initialize can be run in many ways
|
323
|
+
</p>
|
324
|
+
<ul>
|
325
|
+
<li><a href="XML.html#M000026">XML.new</a>
|
326
|
+
|
327
|
+
</li>
|
328
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol)
|
329
|
+
|
330
|
+
</li>
|
331
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol, {attributes})
|
332
|
+
|
333
|
+
</li>
|
334
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol, "<a
|
335
|
+
href="XML.html#M000050">children</a>", "more", <a
|
336
|
+
href="XML.html#M000026">XML.new(...)</a>)
|
337
|
+
|
338
|
+
</li>
|
339
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol, {attributes},
|
340
|
+
"and", "<a href="XML.html#M000050">children</a>")
|
341
|
+
|
342
|
+
</li>
|
343
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol) { monadic code }
|
344
|
+
|
345
|
+
</li>
|
346
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol, {attributes}) { monadic
|
347
|
+
code }
|
348
|
+
|
349
|
+
</li>
|
350
|
+
</ul>
|
351
|
+
<p>
|
352
|
+
Or even:
|
353
|
+
</p>
|
354
|
+
<ul>
|
355
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol, "<a
|
356
|
+
href="XML.html#M000050">children</a>") { and some monadic code }
|
357
|
+
|
358
|
+
</li>
|
359
|
+
<li><a href="XML.html#M000026">XML.new</a>(:tag_symbol, {attributes}, "<a
|
360
|
+
href="XML.html#M000050">children</a>") { and some monadic code }
|
361
|
+
|
362
|
+
</li>
|
363
|
+
</ul>
|
364
|
+
<p>
|
365
|
+
But typically you won‘t be mixing these two style
|
366
|
+
</p>
|
367
|
+
<p>
|
368
|
+
Attribute values can will be converted to strings
|
369
|
+
</p>
|
370
|
+
</div>
|
371
|
+
<div class="sourcecode">
|
372
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000026_source')" id="l_M000026_source">show source</a> ]</p>
|
373
|
+
<div id="M000026_source" class="dyn-source">
|
374
|
+
<pre>
|
375
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 773</span>
|
376
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
377
|
+
<span class="ruby-ivar">@name</span> = <span class="ruby-keyword kw">nil</span>
|
378
|
+
<span class="ruby-ivar">@attrs</span> = {}
|
379
|
+
<span class="ruby-ivar">@contents</span> = []
|
380
|
+
<span class="ruby-ivar">@name</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
|
381
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>
|
382
|
+
<span class="ruby-identifier">args</span>.<span class="ruby-identifier">shift</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>
|
383
|
+
<span class="ruby-comment cmt"># Do automatic conversion here</span>
|
384
|
+
<span class="ruby-comment cmt"># This also assures that the hashes are *not* shared</span>
|
385
|
+
<span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">v</span>
|
386
|
+
}
|
387
|
+
<span class="ruby-keyword kw">end</span>
|
388
|
+
<span class="ruby-comment cmt"># Expand Arrays passed as arguments</span>
|
389
|
+
<span class="ruby-keyword kw">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">args</span>
|
390
|
+
<span class="ruby-comment cmt"># FIXME: We'd rather not have people say @name = :foo there :-)</span>
|
391
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">blk</span>
|
392
|
+
<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
393
|
+
<span class="ruby-keyword kw">end</span>
|
394
|
+
<span class="ruby-keyword kw">end</span>
|
395
|
+
</pre>
|
396
|
+
</div>
|
397
|
+
</div>
|
398
|
+
</div>
|
399
|
+
<div class="method">
|
400
|
+
<div class="title">
|
401
|
+
<a name="M000022"></a><b>parse</b>(stream, options={})
|
402
|
+
</div>
|
403
|
+
<div class="description">
|
404
|
+
<p>
|
405
|
+
Parse <a href="XML.html">XML</a> using REXML. Available options:
|
406
|
+
</p>
|
407
|
+
<ul>
|
408
|
+
<li>:extra_entities => Proc or <a href="Hash.html">Hash</a> (default = nil)
|
409
|
+
|
410
|
+
</li>
|
411
|
+
<li>:remove_pretty_printing => true/false (default = false)
|
412
|
+
|
413
|
+
</li>
|
414
|
+
<li>:comments => true/false (default = false)
|
415
|
+
|
416
|
+
</li>
|
417
|
+
<li>:pi => true/false (default = false)
|
418
|
+
|
419
|
+
</li>
|
420
|
+
<li>:normalize => true/false (default = false) - normalize
|
421
|
+
|
422
|
+
</li>
|
423
|
+
<li>:multiple_roots => true/false (default=false) - document
|
424
|
+
|
425
|
+
<pre>
|
426
|
+
can have any number of roots (instread of one).
|
427
|
+
Return all in an array instead of root/nil.
|
428
|
+
Also include non-elements (String/PI/Comment) in the return set !!!
|
429
|
+
</pre>
|
430
|
+
</li>
|
431
|
+
</ul>
|
432
|
+
<p>
|
433
|
+
FIXME: :comments/:pi will break everything if there are comments/PIs
|
434
|
+
outside document root. Now PIs are outside the document root more often
|
435
|
+
than not, so we‘re pretty much screwed here.
|
436
|
+
</p>
|
437
|
+
<p>
|
438
|
+
FIXME: Integrate all kinds of <a href="XML.html#M000022">parse</a>, and
|
439
|
+
make them support extra options
|
440
|
+
</p>
|
441
|
+
<p>
|
442
|
+
FIXME: Benchmark <a href="XML.html#M000046">normalize!</a>
|
443
|
+
</p>
|
444
|
+
<p>
|
445
|
+
FIXME: Benchmark <a href="XML.html#M000042">dup</a>-based Enumerable
|
446
|
+
methods
|
447
|
+
</p>
|
448
|
+
<p>
|
449
|
+
FIXME: Make it possible to include bogus XML_Document superparent,
|
450
|
+
</p>
|
451
|
+
<pre>
|
452
|
+
and to make it support out-of-root PIs/Comments
|
453
|
+
</pre>
|
454
|
+
</div>
|
455
|
+
<div class="sourcecode">
|
456
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000022_source')" id="l_M000022_source">show source</a> ]</p>
|
457
|
+
<div id="M000022_source" class="dyn-source">
|
458
|
+
<pre>
|
459
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 655</span>
|
460
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">stream</span>, <span class="ruby-identifier">options</span>={})
|
461
|
+
<span class="ruby-identifier">extra_entities</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:extra_entities</span>]
|
462
|
+
|
463
|
+
<span class="ruby-identifier">parser</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Parsers</span><span class="ruby-operator">::</span><span class="ruby-constant">BaseParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">stream</span>
|
464
|
+
<span class="ruby-identifier">stack</span> = [[]]
|
465
|
+
|
466
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
467
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">pull</span>
|
468
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">0</span>]
|
469
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:start_element</span>
|
470
|
+
<span class="ruby-identifier">attrs</span> = {}
|
471
|
+
<span class="ruby-identifier">event</span>[<span class="ruby-value">2</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> <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">xml_unescape</span>(<span class="ruby-identifier">extra_entities</span>) }
|
472
|
+
<span class="ruby-identifier">stack</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">event</span>[<span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>])
|
473
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-2</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>]
|
474
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_element</span>
|
475
|
+
<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
|
476
|
+
<span class="ruby-comment cmt"># Needs unescaping</span>
|
477
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:text</span>
|
478
|
+
<span class="ruby-identifier">e</span> = <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">xml_unescape</span>(<span class="ruby-identifier">extra_entities</span>)
|
479
|
+
<span class="ruby-comment cmt"># Either inside root or in multi-root mode</span>
|
480
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:multiple_roots</span>]
|
481
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">e</span>
|
482
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/\S/</span>
|
483
|
+
<span class="ruby-comment cmt"># Ignore out-of-root whitespace in single-root mode</span>
|
484
|
+
<span class="ruby-keyword kw">else</span>
|
485
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-node">"Non-whitespace text out of document root (and not in multiroot mode): #{event[1]}"</span>
|
486
|
+
<span class="ruby-keyword kw">end</span>
|
487
|
+
<span class="ruby-comment cmt"># CDATA is already unescaped</span>
|
488
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:cdata</span>
|
489
|
+
<span class="ruby-identifier">e</span> = <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>]
|
490
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:multiple_roots</span>]
|
491
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">e</span>
|
492
|
+
<span class="ruby-keyword kw">else</span>
|
493
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-value str">"CDATA out of the document root"</span>
|
494
|
+
<span class="ruby-keyword kw">end</span>
|
495
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:comment</span>
|
496
|
+
<span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:comments</span>]
|
497
|
+
<span class="ruby-identifier">e</span> = <span class="ruby-constant">XML_Comment</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>])
|
498
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:multiple_roots</span>]
|
499
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">e</span>
|
500
|
+
<span class="ruby-keyword kw">else</span>
|
501
|
+
<span class="ruby-comment cmt"># FIXME: Ugly !</span>
|
502
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-value str">"Comments out of the document root"</span>
|
503
|
+
<span class="ruby-keyword kw">end</span>
|
504
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:processing_instruction</span>
|
505
|
+
<span class="ruby-comment cmt"># FIXME: Real PI node</span>
|
506
|
+
<span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:pi</span>]
|
507
|
+
<span class="ruby-identifier">e</span> = <span class="ruby-constant">XML_PI</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>], <span class="ruby-identifier">event</span>[<span class="ruby-value">2</span>])
|
508
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:multiple_roots</span>]
|
509
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">e</span>
|
510
|
+
<span class="ruby-keyword kw">else</span>
|
511
|
+
<span class="ruby-comment cmt"># FIXME: Ugly !</span>
|
512
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-value str">"Processing instruction out of the document root"</span>
|
513
|
+
<span class="ruby-keyword kw">end</span>
|
514
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_document</span>
|
515
|
+
<span class="ruby-keyword kw">break</span>
|
516
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:xmldecl</span>,<span class="ruby-identifier">:start_doctype</span>,<span class="ruby-identifier">:end_doctype</span>,<span class="ruby-identifier">:elementdecl</span>
|
517
|
+
<span class="ruby-comment cmt"># Positivery ignore</span>
|
518
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:externalentity</span>,<span class="ruby-identifier">:entity</span>,<span class="ruby-identifier">:attlistdecl</span>,<span class="ruby-identifier">:notationdecl</span>
|
519
|
+
<span class="ruby-comment cmt"># Ignore ???</span>
|
520
|
+
<span class="ruby-comment cmt">#print "Ignored XML event #{event[0]} when parsing\n"</span>
|
521
|
+
<span class="ruby-keyword kw">else</span>
|
522
|
+
<span class="ruby-comment cmt"># Huh ? What's that ?</span>
|
523
|
+
<span class="ruby-comment cmt">#print "Unknown XML event #{event[0]} when parsing\n"</span>
|
524
|
+
<span class="ruby-keyword kw">end</span>
|
525
|
+
<span class="ruby-keyword kw">end</span>
|
526
|
+
<span class="ruby-identifier">roots</span> = <span class="ruby-identifier">stack</span>[<span class="ruby-value">0</span>]
|
527
|
+
|
528
|
+
<span class="ruby-identifier">roots</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">root</span><span class="ruby-operator">|</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">remove_pretty_printing!</span>} <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:remove_pretty_printing</span>]
|
529
|
+
<span class="ruby-comment cmt"># :remove_pretty_printing does :normalize anyway</span>
|
530
|
+
<span class="ruby-identifier">roots</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">root</span><span class="ruby-operator">|</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">normalize!</span>} <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:normalize</span>]
|
531
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:multiple_roots</span>]
|
532
|
+
<span class="ruby-identifier">roots</span>
|
533
|
+
<span class="ruby-keyword kw">else</span>
|
534
|
+
<span class="ruby-identifier">roots</span>[<span class="ruby-value">0</span>]
|
535
|
+
<span class="ruby-keyword kw">end</span>
|
536
|
+
<span class="ruby-keyword kw">end</span>
|
537
|
+
</pre>
|
538
|
+
</div>
|
539
|
+
</div>
|
540
|
+
</div>
|
541
|
+
<div class="method">
|
542
|
+
<div class="title">
|
543
|
+
<a name="M000020"></a><b>parse_as_twigs</b>(stream) {|node| ...}
|
544
|
+
</div>
|
545
|
+
<div class="description">
|
546
|
+
<p>
|
547
|
+
Parse <a href="XML.html">XML</a> in mixed stream/tree mode Basically the
|
548
|
+
idea is that every time we get start element, we ask the block what to do
|
549
|
+
about it. If it wants a tree below it, it should call e.tree If a tree was
|
550
|
+
requested, elements below the current one are <b>not</b> processed. If it
|
551
|
+
wasn‘t, they are.
|
552
|
+
</p>
|
553
|
+
<p>
|
554
|
+
For example:
|
555
|
+
</p>
|
556
|
+
<pre>
|
557
|
+
<foo><bar/></foo><foo2/>
|
558
|
+
yield <foo> ... </foo>
|
559
|
+
.complete! called
|
560
|
+
process <foo2> next
|
561
|
+
</pre>
|
562
|
+
<p>
|
563
|
+
But:
|
564
|
+
</p>
|
565
|
+
<pre>
|
566
|
+
<foo><bar/></foo><foo2/>
|
567
|
+
yield <foo> ... </foo>
|
568
|
+
.complete! not called
|
569
|
+
process <bar> next
|
570
|
+
</pre>
|
571
|
+
<p>
|
572
|
+
FIXME: yielded values are not reusable for now FIXME: make more
|
573
|
+
object-oriented
|
574
|
+
</p>
|
575
|
+
</div>
|
576
|
+
<div class="sourcecode">
|
577
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000020_source')" id="l_M000020_source">show source</a> ]</p>
|
578
|
+
<div id="M000020_source" class="dyn-source">
|
579
|
+
<pre>
|
580
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 537</span>
|
581
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse_as_twigs</span>(<span class="ruby-identifier">stream</span>)
|
582
|
+
<span class="ruby-identifier">parser</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Parsers</span><span class="ruby-operator">::</span><span class="ruby-constant">BaseParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">stream</span>
|
583
|
+
<span class="ruby-comment cmt"># We don't really need to keep the stack ;-)</span>
|
584
|
+
<span class="ruby-identifier">stack</span> = []
|
585
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
586
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">pull</span>
|
587
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">0</span>]
|
588
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:start_element</span>
|
589
|
+
<span class="ruby-comment cmt"># Now the evil part evil</span>
|
590
|
+
<span class="ruby-identifier">attrs</span> = {}
|
591
|
+
<span class="ruby-identifier">event</span>[<span class="ruby-value">2</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> <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">xml_unescape</span>}
|
592
|
+
<span class="ruby-identifier">node</span> = <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">attrs</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">event</span>[<span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>])
|
593
|
+
|
594
|
+
<span class="ruby-comment cmt"># I can't say it's superelegant</span>
|
595
|
+
<span class="ruby-keyword kw">class</span> <span class="ruby-operator"><<</span><span class="ruby-identifier">node</span>
|
596
|
+
<span class="ruby-identifier">attr_accessor</span> <span class="ruby-identifier">:do_complete</span>
|
597
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">complete!</span>
|
598
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@do_complete</span>
|
599
|
+
<span class="ruby-ivar">@do_complete</span>.<span class="ruby-identifier">call</span>
|
600
|
+
<span class="ruby-ivar">@do_complete</span> = <span class="ruby-keyword kw">nil</span>
|
601
|
+
<span class="ruby-keyword kw">end</span>
|
602
|
+
<span class="ruby-keyword kw">end</span>
|
603
|
+
<span class="ruby-keyword kw">end</span>
|
604
|
+
<span class="ruby-identifier">node</span>.<span class="ruby-identifier">do_complete</span> = <span class="ruby-identifier">proc</span>{
|
605
|
+
<span class="ruby-identifier">parse_subtree</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">parser</span>)
|
606
|
+
}
|
607
|
+
|
608
|
+
<span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">node</span>)
|
609
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">do_complete</span>
|
610
|
+
<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">node</span>
|
611
|
+
<span class="ruby-identifier">node</span>.<span class="ruby-identifier">do_complete</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># It's too late, complete! shouldn't do anything now</span>
|
612
|
+
<span class="ruby-keyword kw">end</span>
|
613
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_element</span>
|
614
|
+
<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
|
615
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_document</span>
|
616
|
+
<span class="ruby-keyword kw">return</span>
|
617
|
+
<span class="ruby-keyword kw">else</span>
|
618
|
+
<span class="ruby-comment cmt"># FIXME: Do the right thing.</span>
|
619
|
+
<span class="ruby-comment cmt"># For now, ignore *everything* else</span>
|
620
|
+
<span class="ruby-comment cmt"># This is totally incorrect, user might want to </span>
|
621
|
+
<span class="ruby-comment cmt"># see text, comments and stuff like that anyway</span>
|
622
|
+
<span class="ruby-keyword kw">end</span>
|
623
|
+
<span class="ruby-keyword kw">end</span>
|
624
|
+
<span class="ruby-keyword kw">end</span>
|
625
|
+
</pre>
|
626
|
+
</div>
|
627
|
+
</div>
|
628
|
+
</div>
|
629
|
+
<div class="method">
|
630
|
+
<div class="title">
|
631
|
+
<a name="M000023"></a><b>parse_sequence</b>(stream, options={})
|
632
|
+
</div>
|
633
|
+
<div class="description">
|
634
|
+
<p>
|
635
|
+
Parse a sequence. Equivalent to <a
|
636
|
+
href="XML.html#M000022">XML.parse</a>(stream, :multiple_roots => true).
|
637
|
+
</p>
|
638
|
+
</div>
|
639
|
+
<div class="sourcecode">
|
640
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000023_source')" id="l_M000023_source">show source</a> ]</p>
|
641
|
+
<div id="M000023_source" class="dyn-source">
|
642
|
+
<pre>
|
643
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 734</span>
|
644
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse_sequence</span>(<span class="ruby-identifier">stream</span>, <span class="ruby-identifier">options</span>={})
|
645
|
+
<span class="ruby-identifier">o</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">dup</span>
|
646
|
+
<span class="ruby-identifier">o</span>[<span class="ruby-identifier">:multiple_roots</span>] = <span class="ruby-keyword kw">true</span>
|
647
|
+
<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">stream</span>, <span class="ruby-identifier">o</span>)
|
648
|
+
<span class="ruby-keyword kw">end</span>
|
649
|
+
</pre>
|
650
|
+
</div>
|
651
|
+
</div>
|
652
|
+
</div>
|
653
|
+
<div class="method">
|
654
|
+
<div class="title">
|
655
|
+
<a name="M000021"></a><b>parse_subtree</b>(start_node, parser)
|
656
|
+
</div>
|
657
|
+
<div class="description">
|
658
|
+
<p>
|
659
|
+
Basically it‘s a copy of self.parse, ugly …
|
660
|
+
</p>
|
661
|
+
</div>
|
662
|
+
<div class="sourcecode">
|
663
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000021_source')" id="l_M000021_source">show source</a> ]</p>
|
664
|
+
<div id="M000021_source" class="dyn-source">
|
665
|
+
<pre>
|
666
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 583</span>
|
667
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse_subtree</span>(<span class="ruby-identifier">start_node</span>, <span class="ruby-identifier">parser</span>)
|
668
|
+
<span class="ruby-identifier">stack</span> = [<span class="ruby-identifier">start_node</span>]
|
669
|
+
<span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">nil</span>
|
670
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
671
|
+
<span class="ruby-identifier">event</span> = <span class="ruby-identifier">parser</span>.<span class="ruby-identifier">pull</span>
|
672
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">0</span>]
|
673
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:start_element</span>
|
674
|
+
<span class="ruby-identifier">attrs</span> = {}
|
675
|
+
<span class="ruby-identifier">event</span>[<span class="ruby-value">2</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> <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">v</span>.<span class="ruby-identifier">xml_unescape</span>}
|
676
|
+
<span class="ruby-identifier">stack</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">attrs</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">event</span>[<span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>])
|
677
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
|
678
|
+
<span class="ruby-identifier">res</span> = <span class="ruby-identifier">stack</span>[<span class="ruby-value">0</span>]
|
679
|
+
<span class="ruby-keyword kw">else</span>
|
680
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-2</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>]
|
681
|
+
<span class="ruby-keyword kw">end</span>
|
682
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_element</span>
|
683
|
+
<span class="ruby-identifier">stack</span>.<span class="ruby-identifier">pop</span>
|
684
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span> <span class="ruby-operator">==</span> []
|
685
|
+
<span class="ruby-comment cmt"># Needs unescaping</span>
|
686
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:text</span>
|
687
|
+
<span class="ruby-comment cmt"># Ignore whitespace</span>
|
688
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
689
|
+
<span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/\S/</span>
|
690
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-value str">"Non-whitespace text out of document root"</span>
|
691
|
+
<span class="ruby-keyword kw">end</span>
|
692
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">xml_unescape</span>
|
693
|
+
<span class="ruby-comment cmt"># CDATA is already unescaped</span>
|
694
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:cdata</span>
|
695
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
696
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-value str">"CDATA out of the document root"</span>
|
697
|
+
<span class="ruby-keyword kw">end</span>
|
698
|
+
<span class="ruby-identifier">stack</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">event</span>[<span class="ruby-value">1</span>]
|
699
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:end_document</span>
|
700
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-value str">"Parse error: end_document inside a subtree, tags are not balanced"</span>
|
701
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:xmldecl</span>,<span class="ruby-identifier">:start_doctype</span>,<span class="ruby-identifier">:end_doctype</span>,<span class="ruby-identifier">:elementdecl</span>,<span class="ruby-identifier">:processing_instruction</span>
|
702
|
+
<span class="ruby-comment cmt"># Positivery ignore</span>
|
703
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:comment</span>,<span class="ruby-identifier">:externalentity</span>,<span class="ruby-identifier">:entity</span>,<span class="ruby-identifier">:attlistdecl</span>,<span class="ruby-identifier">:notationdecl</span>
|
704
|
+
<span class="ruby-comment cmt"># Ignore ???</span>
|
705
|
+
<span class="ruby-comment cmt">#print "Ignored XML event #{event[0]} when parsing\n"</span>
|
706
|
+
<span class="ruby-keyword kw">else</span>
|
707
|
+
<span class="ruby-comment cmt"># Huh ? What's that ?</span>
|
708
|
+
<span class="ruby-comment cmt">#print "Unknown XML event #{event[0]} when parsing\n"</span>
|
709
|
+
<span class="ruby-keyword kw">end</span>
|
710
|
+
<span class="ruby-keyword kw">end</span>
|
711
|
+
<span class="ruby-identifier">res</span>
|
712
|
+
|
713
|
+
<span class="ruby-keyword kw">end</span>
|
714
|
+
</pre>
|
715
|
+
</div>
|
716
|
+
</div>
|
717
|
+
</div>
|
718
|
+
<div class="method">
|
719
|
+
<div class="title">
|
720
|
+
<a name="M000024"></a><b>renormalize</b>(stream)
|
721
|
+
</div>
|
722
|
+
<div class="description">
|
723
|
+
<p>
|
724
|
+
Renormalize a string containing <a href="XML.html">XML</a> document
|
725
|
+
</p>
|
726
|
+
</div>
|
727
|
+
<div class="sourcecode">
|
728
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000024_source')" id="l_M000024_source">show source</a> ]</p>
|
729
|
+
<div id="M000024_source" class="dyn-source">
|
730
|
+
<pre>
|
731
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 741</span>
|
732
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">renormalize</span>(<span class="ruby-identifier">stream</span>)
|
733
|
+
<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">stream</span>).<span class="ruby-identifier">to_s</span>
|
734
|
+
<span class="ruby-keyword kw">end</span>
|
735
|
+
</pre>
|
736
|
+
</div>
|
737
|
+
</div>
|
738
|
+
</div>
|
739
|
+
<div class="method">
|
740
|
+
<div class="title">
|
741
|
+
<a name="M000025"></a><b>renormalize_sequence</b>(stream)
|
742
|
+
</div>
|
743
|
+
<div class="description">
|
744
|
+
<p>
|
745
|
+
Renormalize a string containing a sequence of <a href="XML.html">XML</a>
|
746
|
+
documents and strings XMLrenormalize_sequence("<hello />,
|
747
|
+
<world></world>!") => "<hello/>,
|
748
|
+
<world/>!"
|
749
|
+
</p>
|
750
|
+
</div>
|
751
|
+
<div class="sourcecode">
|
752
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000025_source')" id="l_M000025_source">show source</a> ]</p>
|
753
|
+
<div id="M000025_source" class="dyn-source">
|
754
|
+
<pre>
|
755
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 749</span>
|
756
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">renormalize_sequence</span>(<span class="ruby-identifier">stream</span>)
|
757
|
+
<span class="ruby-identifier">parse_sequence</span>(<span class="ruby-identifier">stream</span>).<span class="ruby-identifier">to_s</span>
|
758
|
+
<span class="ruby-keyword kw">end</span>
|
759
|
+
</pre>
|
760
|
+
</div>
|
761
|
+
</div>
|
762
|
+
</div>
|
763
|
+
<div class="sectiontitle">Public Instance methods</div>
|
764
|
+
<div class="method">
|
765
|
+
<div class="title">
|
766
|
+
<a name="M000031"></a><b><<</b>(cnt)
|
767
|
+
</div>
|
768
|
+
<div class="description">
|
769
|
+
<p>
|
770
|
+
Add <a href="XML.html#M000050">children</a>. Possible uses:
|
771
|
+
</p>
|
772
|
+
<ul>
|
773
|
+
<li>Add single element
|
774
|
+
|
775
|
+
</li>
|
776
|
+
</ul>
|
777
|
+
<pre>
|
778
|
+
self << xml(...)
|
779
|
+
self << "foo"
|
780
|
+
</pre>
|
781
|
+
<p>
|
782
|
+
Add nothing:
|
783
|
+
</p>
|
784
|
+
<pre>
|
785
|
+
self << nil
|
786
|
+
</pre>
|
787
|
+
<p>
|
788
|
+
Add multiple elements (also works recursively):
|
789
|
+
</p>
|
790
|
+
<pre>
|
791
|
+
self << [a, b, c]
|
792
|
+
self << [a, [b, c], d]
|
793
|
+
</pre>
|
794
|
+
</div>
|
795
|
+
<div class="aka">
|
796
|
+
This method is also aliased as
|
797
|
+
<a href="XML.html#M000045">add!</a>
|
798
|
+
</div>
|
799
|
+
<div class="sourcecode">
|
800
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000031_source')" id="l_M000031_source">show source</a> ]</p>
|
801
|
+
<div id="M000031_source" class="dyn-source">
|
802
|
+
<pre>
|
803
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 863</span>
|
804
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator"><<</span>(<span class="ruby-identifier">cnt</span>)
|
805
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cnt</span>.<span class="ruby-identifier">nil?</span>
|
806
|
+
<span class="ruby-comment cmt"># skip</span>
|
807
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cnt</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Array</span>
|
808
|
+
<span class="ruby-identifier">cnt</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">elem</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">elem</span>}
|
809
|
+
<span class="ruby-keyword kw">else</span>
|
810
|
+
<span class="ruby-ivar">@contents</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">cnt</span>
|
811
|
+
<span class="ruby-keyword kw">end</span>
|
812
|
+
<span class="ruby-keyword kw">self</span>
|
813
|
+
<span class="ruby-keyword kw">end</span>
|
814
|
+
</pre>
|
815
|
+
</div>
|
816
|
+
</div>
|
817
|
+
</div>
|
818
|
+
<div class="method">
|
819
|
+
<div class="title">
|
820
|
+
<a name="M000032"></a><b>==</b>(x)
|
821
|
+
</div>
|
822
|
+
<div class="description">
|
823
|
+
<p>
|
824
|
+
Equality test, works as if XMLs were normalized, so:
|
825
|
+
</p>
|
826
|
+
<pre>
|
827
|
+
XML.new(:foo, "Hello, ", "world") == XML.new(:foo, "Hello, world")
|
828
|
+
</pre>
|
829
|
+
</div>
|
830
|
+
<div class="sourcecode">
|
831
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000032_source')" id="l_M000032_source">show source</a> ]</p>
|
832
|
+
<div id="M000032_source" class="dyn-source">
|
833
|
+
<pre>
|
834
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 876</span>
|
835
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">x</span>)
|
836
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
837
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">name</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">attrs</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">attrs</span>
|
838
|
+
<span class="ruby-comment cmt"># Now the hard part, strings can be split in different ways</span>
|
839
|
+
<span class="ruby-comment cmt"># empty string children are possible etc.</span>
|
840
|
+
<span class="ruby-identifier">self_i</span> = <span class="ruby-value">0</span>
|
841
|
+
<span class="ruby-identifier">othr_i</span> = <span class="ruby-value">0</span>
|
842
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-identifier">self_i</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">contents</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">othr_i</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>.<span class="ruby-identifier">size</span>
|
843
|
+
<span class="ruby-comment cmt"># Ignore ""s</span>
|
844
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">""</span>
|
845
|
+
<span class="ruby-identifier">self_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
846
|
+
<span class="ruby-keyword kw">next</span>
|
847
|
+
<span class="ruby-keyword kw">end</span>
|
848
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">""</span>
|
849
|
+
<span class="ruby-identifier">othr_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
850
|
+
<span class="ruby-keyword kw">next</span>
|
851
|
+
<span class="ruby-keyword kw">end</span>
|
852
|
+
|
853
|
+
<span class="ruby-comment cmt"># If one is finished and the other contains non-empty elements,</span>
|
854
|
+
<span class="ruby-comment cmt"># they are not equal</span>
|
855
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">self_i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">contents</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">othr_i</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>.<span class="ruby-identifier">size</span>
|
856
|
+
|
857
|
+
<span class="ruby-comment cmt"># Are they both Strings ?</span>
|
858
|
+
<span class="ruby-comment cmt"># Strings can be divided in different ways, and calling normalize!</span>
|
859
|
+
<span class="ruby-comment cmt"># here would be rather expensive, so let's use this complicated</span>
|
860
|
+
<span class="ruby-comment cmt"># algorithm</span>
|
861
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
862
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>]
|
863
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>]
|
864
|
+
<span class="ruby-identifier">self_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
865
|
+
<span class="ruby-identifier">othr_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
866
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">""</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">b</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">""</span>
|
867
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">b</span>
|
868
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-value str">""</span>
|
869
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-value str">""</span>
|
870
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">b</span>.<span class="ruby-identifier">size</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">b</span>
|
871
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>[<span class="ruby-identifier">b</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
|
872
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
873
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>]
|
874
|
+
<span class="ruby-identifier">othr_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
875
|
+
<span class="ruby-keyword kw">next</span>
|
876
|
+
<span class="ruby-keyword kw">end</span>
|
877
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">b</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">a</span>
|
878
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">b</span>[<span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
|
879
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
880
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>]
|
881
|
+
<span class="ruby-identifier">self_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
882
|
+
<span class="ruby-keyword kw">next</span>
|
883
|
+
<span class="ruby-keyword kw">end</span>
|
884
|
+
<span class="ruby-keyword kw">else</span>
|
885
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
|
886
|
+
<span class="ruby-keyword kw">end</span>
|
887
|
+
<span class="ruby-keyword kw">end</span>
|
888
|
+
<span class="ruby-keyword kw">next</span>
|
889
|
+
<span class="ruby-keyword kw">end</span>
|
890
|
+
|
891
|
+
<span class="ruby-comment cmt"># OK, so at least one of them is not a String.</span>
|
892
|
+
<span class="ruby-comment cmt"># Hopefully they're either both XMLs or one is an XML and the</span>
|
893
|
+
<span class="ruby-comment cmt"># other is a String. It is also possible that contents contains</span>
|
894
|
+
<span class="ruby-comment cmt"># something illegal, but we aren't catching that,</span>
|
895
|
+
<span class="ruby-comment cmt"># so xml(:foo, Garbage.new) is going to at least equal itself.</span>
|
896
|
+
<span class="ruby-comment cmt"># And we aren't, because xml(:foo, Garbage.new) == xml(:bar, Garbage.new)</span>
|
897
|
+
<span class="ruby-comment cmt"># is going to return an honest false, and incoherent sanity</span>
|
898
|
+
<span class="ruby-comment cmt"># check is worse than no sanity check.</span>
|
899
|
+
<span class="ruby-comment cmt">#</span>
|
900
|
+
<span class="ruby-comment cmt"># Oh yeah, they can be XML_PI or XML_Comment. In such case, this</span>
|
901
|
+
<span class="ruby-comment cmt"># is ok.</span>
|
902
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">contents</span>[<span class="ruby-identifier">self_i</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">contents</span>[<span class="ruby-identifier">othr_i</span>]
|
903
|
+
<span class="ruby-identifier">self_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
904
|
+
<span class="ruby-identifier">othr_i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
905
|
+
<span class="ruby-keyword kw">end</span>
|
906
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
907
|
+
<span class="ruby-keyword kw">end</span>
|
908
|
+
</pre>
|
909
|
+
</div>
|
910
|
+
</div>
|
911
|
+
</div>
|
912
|
+
<div class="method">
|
913
|
+
<div class="title">
|
914
|
+
<a name="M000037"></a><b>=~</b>(pattern)
|
915
|
+
</div>
|
916
|
+
<div class="description">
|
917
|
+
<h1>~ for a few reasonable patterns</h1>
|
918
|
+
</div>
|
919
|
+
<div class="sourcecode">
|
920
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000037_source')" id="l_M000037_source">show source</a> ]</p>
|
921
|
+
<div id="M000037_source" class="dyn-source">
|
922
|
+
<pre>
|
923
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1085</span>
|
924
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">=~</span>(<span class="ruby-identifier">pattern</span>)
|
925
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Symbol</span>
|
926
|
+
<span class="ruby-ivar">@name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">pattern</span>
|
927
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Regexp</span>
|
928
|
+
<span class="ruby-identifier">rv</span> = <span class="ruby-identifier">text</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">pattern</span>
|
929
|
+
<span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># Hash, Pattern_any, Pattern_all</span>
|
930
|
+
<span class="ruby-identifier">pattern</span> <span class="ruby-operator">===</span> <span class="ruby-keyword kw">self</span>
|
931
|
+
<span class="ruby-keyword kw">end</span>
|
932
|
+
<span class="ruby-keyword kw">end</span>
|
933
|
+
</pre>
|
934
|
+
</div>
|
935
|
+
</div>
|
936
|
+
</div>
|
937
|
+
<div class="method">
|
938
|
+
<div class="title">
|
939
|
+
<a name="M000029"></a><b>[]</b>(key)
|
940
|
+
</div>
|
941
|
+
<div class="description">
|
942
|
+
<p>
|
943
|
+
Read attributes. Also works with pseudoattributes:
|
944
|
+
</p>
|
945
|
+
<pre>
|
946
|
+
img[:@x] == img.child(:x).text # or nil if there isn't any.
|
947
|
+
</pre>
|
948
|
+
</div>
|
949
|
+
<div class="sourcecode">
|
950
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000029_source')" id="l_M000029_source">show source</a> ]</p>
|
951
|
+
<div id="M000029_source" class="dyn-source">
|
952
|
+
<pre>
|
953
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 820</span>
|
954
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">key</span>)
|
955
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?@</span>
|
956
|
+
<span class="ruby-identifier">tag</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">to_sym</span>
|
957
|
+
<span class="ruby-identifier">c</span> = <span class="ruby-identifier">child</span>(<span class="ruby-identifier">tag</span>)
|
958
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>
|
959
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">text</span>
|
960
|
+
<span class="ruby-keyword kw">else</span>
|
961
|
+
<span class="ruby-keyword kw">nil</span>
|
962
|
+
<span class="ruby-keyword kw">end</span>
|
963
|
+
<span class="ruby-keyword kw">else</span>
|
964
|
+
<span class="ruby-ivar">@attrs</span>[<span class="ruby-identifier">key</span>]
|
965
|
+
<span class="ruby-keyword kw">end</span>
|
966
|
+
<span class="ruby-keyword kw">end</span>
|
967
|
+
</pre>
|
968
|
+
</div>
|
969
|
+
</div>
|
970
|
+
</div>
|
971
|
+
<div class="method">
|
972
|
+
<div class="title">
|
973
|
+
<a name="M000030"></a><b>[]=</b>(key, value)
|
974
|
+
</div>
|
975
|
+
<div class="description">
|
976
|
+
<p>
|
977
|
+
Set attributes. Value is automatically converted to <a
|
978
|
+
href="String.html">String</a>, so you can say:
|
979
|
+
</p>
|
980
|
+
<pre>
|
981
|
+
img[:x] = 200
|
982
|
+
</pre>
|
983
|
+
<p>
|
984
|
+
Also works with pseudoattributes:
|
985
|
+
</p>
|
986
|
+
<pre>
|
987
|
+
foo[:@bar] = "x"
|
988
|
+
</pre>
|
989
|
+
</div>
|
990
|
+
<div class="sourcecode">
|
991
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000030_source')" id="l_M000030_source">show source</a> ]</p>
|
992
|
+
<div id="M000030_source" class="dyn-source">
|
993
|
+
<pre>
|
994
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 839</span>
|
995
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
996
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?@</span>
|
997
|
+
<span class="ruby-identifier">tag</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">to_sym</span>
|
998
|
+
<span class="ruby-identifier">c</span> = <span class="ruby-identifier">child</span>(<span class="ruby-identifier">tag</span>)
|
999
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>
|
1000
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">contents</span> = [<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>]
|
1001
|
+
<span class="ruby-keyword kw">else</span>
|
1002
|
+
<span class="ruby-keyword kw">self</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">tag</span>, <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>)
|
1003
|
+
<span class="ruby-keyword kw">end</span>
|
1004
|
+
<span class="ruby-keyword kw">else</span>
|
1005
|
+
<span class="ruby-ivar">@attrs</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>
|
1006
|
+
<span class="ruby-keyword kw">end</span>
|
1007
|
+
<span class="ruby-keyword kw">end</span>
|
1008
|
+
</pre>
|
1009
|
+
</div>
|
1010
|
+
</div>
|
1011
|
+
</div>
|
1012
|
+
<div class="method">
|
1013
|
+
<div class="title">
|
1014
|
+
<a name="M000045"></a><b>add!</b>(cnt)
|
1015
|
+
</div>
|
1016
|
+
<div class="description">
|
1017
|
+
<p>
|
1018
|
+
Alias for #<<
|
1019
|
+
</p>
|
1020
|
+
</div>
|
1021
|
+
</div>
|
1022
|
+
<div class="method">
|
1023
|
+
<div class="title">
|
1024
|
+
<a name="M000040"></a><b>add_pretty_printing!</b>()
|
1025
|
+
</div>
|
1026
|
+
<div class="description">
|
1027
|
+
<p>
|
1028
|
+
Add pretty-printing whitespace. Also normalizes the <a
|
1029
|
+
href="XML.html">XML</a>.
|
1030
|
+
</p>
|
1031
|
+
</div>
|
1032
|
+
<div class="sourcecode">
|
1033
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000040_source')" id="l_M000040_source">show source</a> ]</p>
|
1034
|
+
<div id="M000040_source" class="dyn-source">
|
1035
|
+
<pre>
|
1036
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1121</span>
|
1037
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_pretty_printing!</span>
|
1038
|
+
<span class="ruby-identifier">normalize!</span>
|
1039
|
+
<span class="ruby-identifier">real_add_pretty_printing!</span>
|
1040
|
+
<span class="ruby-identifier">normalize!</span>
|
1041
|
+
<span class="ruby-keyword kw">end</span>
|
1042
|
+
</pre>
|
1043
|
+
</div>
|
1044
|
+
</div>
|
1045
|
+
</div>
|
1046
|
+
<div class="method">
|
1047
|
+
<div class="title">
|
1048
|
+
<a name="M000048"></a><b>child</b>(pat=nil, *rest)
|
1049
|
+
</div>
|
1050
|
+
<div class="description">
|
1051
|
+
<p>
|
1052
|
+
Equivalent to node.children(pat, *rest)[0] Returns nil if there
|
1053
|
+
aren‘t any matching <a href="XML.html#M000050">children</a>
|
1054
|
+
</p>
|
1055
|
+
</div>
|
1056
|
+
<div class="sourcecode">
|
1057
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000048_source')" id="l_M000048_source">show source</a> ]</p>
|
1058
|
+
<div id="M000048_source" class="dyn-source">
|
1059
|
+
<pre>
|
1060
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1205</span>
|
1061
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">child</span>(<span class="ruby-identifier">pat</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>)
|
1062
|
+
<span class="ruby-identifier">children</span>(<span class="ruby-identifier">pat</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1063
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">c</span>
|
1064
|
+
}
|
1065
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
1066
|
+
<span class="ruby-keyword kw">end</span>
|
1067
|
+
</pre>
|
1068
|
+
</div>
|
1069
|
+
</div>
|
1070
|
+
</div>
|
1071
|
+
<div class="method">
|
1072
|
+
<div class="title">
|
1073
|
+
<a name="M000050"></a><b>children</b>(pat=nil, *rest) {|c if block_given?| ...}
|
1074
|
+
</div>
|
1075
|
+
<div class="description">
|
1076
|
+
<p>
|
1077
|
+
<a href="XML.html#M000050">XML#children</a>(pattern, more_patterns) Return
|
1078
|
+
all <a href="XML.html#M000050">children</a> of a node with tags matching
|
1079
|
+
tag. Also:
|
1080
|
+
</p>
|
1081
|
+
<ul>
|
1082
|
+
<li><a href="XML.html#M000050">children</a>(:a, :b) == <a
|
1083
|
+
href="XML.html#M000050">children</a>(:a).<a
|
1084
|
+
href="XML.html#M000050">children</a>(:b)
|
1085
|
+
|
1086
|
+
</li>
|
1087
|
+
<li><a href="XML.html#M000050">children</a>(:a, :*, :c) == <a
|
1088
|
+
href="XML.html#M000050">children</a>(:a).<a
|
1089
|
+
href="XML.html#M000051">descendants</a>(:c)
|
1090
|
+
|
1091
|
+
</li>
|
1092
|
+
</ul>
|
1093
|
+
</div>
|
1094
|
+
<div class="sourcecode">
|
1095
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000050_source')" id="l_M000050_source">show source</a> ]</p>
|
1096
|
+
<div id="M000050_source" class="dyn-source">
|
1097
|
+
<pre>
|
1098
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1226</span>
|
1099
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">children</span>(<span class="ruby-identifier">pat</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1100
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">descendants</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pat</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:*</span>
|
1101
|
+
<span class="ruby-identifier">res</span> = []
|
1102
|
+
<span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1103
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pat</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">pat</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">c</span>
|
1104
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rest</span> <span class="ruby-operator">==</span> []
|
1105
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>
|
1106
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">c</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
1107
|
+
<span class="ruby-keyword kw">else</span>
|
1108
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">children</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1109
|
+
<span class="ruby-keyword kw">end</span>
|
1110
|
+
<span class="ruby-keyword kw">end</span>
|
1111
|
+
}
|
1112
|
+
<span class="ruby-identifier">res</span>
|
1113
|
+
<span class="ruby-keyword kw">end</span>
|
1114
|
+
</pre>
|
1115
|
+
</div>
|
1116
|
+
</div>
|
1117
|
+
</div>
|
1118
|
+
<div class="method">
|
1119
|
+
<div class="title">
|
1120
|
+
<a name="M000014"></a><b>children_sort_by</b>(*args, &blk)
|
1121
|
+
</div>
|
1122
|
+
<div class="description">
|
1123
|
+
<p>
|
1124
|
+
Sort <a href="XML.html#M000050">children</a> of <a href="XML.html">XML</a>
|
1125
|
+
element.
|
1126
|
+
</p>
|
1127
|
+
</div>
|
1128
|
+
<div class="sourcecode">
|
1129
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000014_source')" id="l_M000014_source">show source</a> ]</p>
|
1130
|
+
<div id="M000014_source" class="dyn-source">
|
1131
|
+
<pre>
|
1132
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 391</span>
|
1133
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">children_sort_by</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1134
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>{ <span class="ruby-ivar">@contents</span> = <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>) }
|
1135
|
+
<span class="ruby-keyword kw">end</span>
|
1136
|
+
</pre>
|
1137
|
+
</div>
|
1138
|
+
</div>
|
1139
|
+
</div>
|
1140
|
+
<div class="method">
|
1141
|
+
<div class="title">
|
1142
|
+
<a name="M000052"></a><b>deep_map</b>(pat) {|self| ...}
|
1143
|
+
</div>
|
1144
|
+
<div class="description">
|
1145
|
+
<p>
|
1146
|
+
Change elements based on pattern
|
1147
|
+
</p>
|
1148
|
+
</div>
|
1149
|
+
<div class="sourcecode">
|
1150
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000052_source')" id="l_M000052_source">show source</a> ]</p>
|
1151
|
+
<div id="M000052_source" class="dyn-source">
|
1152
|
+
<pre>
|
1153
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1269</span>
|
1154
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deep_map</span>(<span class="ruby-identifier">pat</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1155
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">pat</span>
|
1156
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>
|
1157
|
+
<span class="ruby-keyword kw">else</span>
|
1158
|
+
<span class="ruby-identifier">r</span> = <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attrs</span>)
|
1159
|
+
<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1160
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1161
|
+
<span class="ruby-identifier">r</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">deep_map</span>(<span class="ruby-identifier">pat</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1162
|
+
<span class="ruby-keyword kw">else</span>
|
1163
|
+
<span class="ruby-identifier">r</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>
|
1164
|
+
<span class="ruby-keyword kw">end</span>
|
1165
|
+
}
|
1166
|
+
<span class="ruby-identifier">r</span>
|
1167
|
+
<span class="ruby-keyword kw">end</span>
|
1168
|
+
<span class="ruby-keyword kw">end</span>
|
1169
|
+
</pre>
|
1170
|
+
</div>
|
1171
|
+
</div>
|
1172
|
+
</div>
|
1173
|
+
<div class="method">
|
1174
|
+
<div class="title">
|
1175
|
+
<a name="M000049"></a><b>descendant</b>(pat=nil, *rest)
|
1176
|
+
</div>
|
1177
|
+
<div class="description">
|
1178
|
+
<p>
|
1179
|
+
Equivalent to node.descendants(pat, *rest)[0] Returns nil if there
|
1180
|
+
aren‘t any matching <a href="XML.html#M000051">descendants</a>
|
1181
|
+
</p>
|
1182
|
+
</div>
|
1183
|
+
<div class="sourcecode">
|
1184
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000049_source')" id="l_M000049_source">show source</a> ]</p>
|
1185
|
+
<div id="M000049_source" class="dyn-source">
|
1186
|
+
<pre>
|
1187
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1214</span>
|
1188
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">descendant</span>(<span class="ruby-identifier">pat</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>)
|
1189
|
+
<span class="ruby-identifier">descendants</span>(<span class="ruby-identifier">pat</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1190
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">c</span>
|
1191
|
+
}
|
1192
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
1193
|
+
<span class="ruby-keyword kw">end</span>
|
1194
|
+
</pre>
|
1195
|
+
</div>
|
1196
|
+
</div>
|
1197
|
+
</div>
|
1198
|
+
<div class="method">
|
1199
|
+
<div class="title">
|
1200
|
+
<a name="M000051"></a><b>descendants</b>(pat=nil, *rest) {|c if block_given?| ...}
|
1201
|
+
</div>
|
1202
|
+
<div class="description">
|
1203
|
+
<ul>
|
1204
|
+
<li><a href="XML.html#M000051">XML#descendants</a>
|
1205
|
+
|
1206
|
+
</li>
|
1207
|
+
<li><a href="XML.html#M000051">XML#descendants(pattern)</a>
|
1208
|
+
|
1209
|
+
</li>
|
1210
|
+
<li><a href="XML.html#M000051">XML#descendants</a>(pattern, more_patterns)
|
1211
|
+
|
1212
|
+
</li>
|
1213
|
+
</ul>
|
1214
|
+
<p>
|
1215
|
+
Return all <a href="XML.html#M000051">descendants</a> of a node matching
|
1216
|
+
the pattern. If pattern==nil, simply return all <a
|
1217
|
+
href="XML.html#M000051">descendants</a>. Optionally run a block on <a
|
1218
|
+
href="XML.html#M000012">each</a> of them if a block was given. If
|
1219
|
+
pattern==nil, also match Strings !
|
1220
|
+
</p>
|
1221
|
+
</div>
|
1222
|
+
<div class="sourcecode">
|
1223
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000051_source')" id="l_M000051_source">show source</a> ]</p>
|
1224
|
+
<div id="M000051_source" class="dyn-source">
|
1225
|
+
<pre>
|
1226
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1250</span>
|
1227
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">descendants</span>(<span class="ruby-identifier">pat</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1228
|
+
<span class="ruby-identifier">res</span> = []
|
1229
|
+
<span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1230
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pat</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">pat</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">c</span>
|
1231
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rest</span> <span class="ruby-operator">==</span> []
|
1232
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>
|
1233
|
+
<span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">c</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
1234
|
+
<span class="ruby-keyword kw">else</span>
|
1235
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">children</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1236
|
+
<span class="ruby-keyword kw">end</span>
|
1237
|
+
<span class="ruby-keyword kw">end</span>
|
1238
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1239
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">descendants</span>(<span class="ruby-identifier">pat</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">rest</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1240
|
+
<span class="ruby-keyword kw">end</span>
|
1241
|
+
}
|
1242
|
+
<span class="ruby-identifier">res</span>
|
1243
|
+
<span class="ruby-keyword kw">end</span>
|
1244
|
+
</pre>
|
1245
|
+
</div>
|
1246
|
+
</div>
|
1247
|
+
</div>
|
1248
|
+
<div class="method">
|
1249
|
+
<div class="title">
|
1250
|
+
<a name="M000042"></a><b>dup</b>(&blk)
|
1251
|
+
</div>
|
1252
|
+
<div class="description">
|
1253
|
+
<p>
|
1254
|
+
This is not a trivial method - first it does a <b>deep</b> copy, second it
|
1255
|
+
takes a block which is instance_eval‘ed, so you can do things like:
|
1256
|
+
</p>
|
1257
|
+
<ul>
|
1258
|
+
<li>node.dup{ @name = :foo }
|
1259
|
+
|
1260
|
+
</li>
|
1261
|
+
<li>node.dup{ self[:color] = "blue" }
|
1262
|
+
|
1263
|
+
</li>
|
1264
|
+
</ul>
|
1265
|
+
</div>
|
1266
|
+
<div class="sourcecode">
|
1267
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000042_source')" id="l_M000042_source">show source</a> ]</p>
|
1268
|
+
<div id="M000042_source" class="dyn-source">
|
1269
|
+
<pre>
|
1270
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1147</span>
|
1271
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1272
|
+
<span class="ruby-identifier">new_obj</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">raw_dup</span>
|
1273
|
+
<span class="ruby-comment cmt"># Attr values stay shared - ugly</span>
|
1274
|
+
<span class="ruby-identifier">new_obj</span>.<span class="ruby-identifier">attrs</span> = <span class="ruby-identifier">new_obj</span>.<span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">dup</span>
|
1275
|
+
<span class="ruby-identifier">new_obj</span>.<span class="ruby-identifier">contents</span> = <span class="ruby-identifier">new_obj</span>.<span class="ruby-identifier">contents</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">dup</span>}
|
1276
|
+
|
1277
|
+
<span class="ruby-identifier">new_obj</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">blk</span>
|
1278
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">new_obj</span>
|
1279
|
+
<span class="ruby-keyword kw">end</span>
|
1280
|
+
</pre>
|
1281
|
+
</div>
|
1282
|
+
</div>
|
1283
|
+
</div>
|
1284
|
+
<div class="method">
|
1285
|
+
<div class="title">
|
1286
|
+
<a name="M000012"></a><b>each</b>(*selector, &blk)
|
1287
|
+
</div>
|
1288
|
+
<div class="description">
|
1289
|
+
<p>
|
1290
|
+
Iterate over <a href="XML.html#M000050">children</a>, possibly with a
|
1291
|
+
selector
|
1292
|
+
</p>
|
1293
|
+
</div>
|
1294
|
+
<div class="sourcecode">
|
1295
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000012_source')" id="l_M000012_source">show source</a> ]</p>
|
1296
|
+
<div id="M000012_source" class="dyn-source">
|
1297
|
+
<pre>
|
1298
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 380</span>
|
1299
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">selector</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1300
|
+
<span class="ruby-identifier">children</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">selector</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1301
|
+
<span class="ruby-keyword kw">self</span>
|
1302
|
+
<span class="ruby-keyword kw">end</span>
|
1303
|
+
</pre>
|
1304
|
+
</div>
|
1305
|
+
</div>
|
1306
|
+
</div>
|
1307
|
+
<div class="method">
|
1308
|
+
<div class="title">
|
1309
|
+
<a name="M000034"></a><b>exec!</b>(&blk)
|
1310
|
+
</div>
|
1311
|
+
<div class="description">
|
1312
|
+
<p>
|
1313
|
+
Make monadic interface more "official"
|
1314
|
+
</p>
|
1315
|
+
<ul>
|
1316
|
+
<li>node.exec! { foo!; bar! }
|
1317
|
+
|
1318
|
+
</li>
|
1319
|
+
</ul>
|
1320
|
+
<p>
|
1321
|
+
is equivalent to
|
1322
|
+
</p>
|
1323
|
+
<ul>
|
1324
|
+
<li>node << xml(:foo) << xml(:bar)
|
1325
|
+
|
1326
|
+
</li>
|
1327
|
+
</ul>
|
1328
|
+
</div>
|
1329
|
+
<div class="sourcecode">
|
1330
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000034_source')" id="l_M000034_source">show source</a> ]</p>
|
1331
|
+
<div id="M000034_source" class="dyn-source">
|
1332
|
+
<pre>
|
1333
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 965</span>
|
1334
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exec!</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1335
|
+
<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1336
|
+
<span class="ruby-keyword kw">end</span>
|
1337
|
+
</pre>
|
1338
|
+
</div>
|
1339
|
+
</div>
|
1340
|
+
</div>
|
1341
|
+
<div class="method">
|
1342
|
+
<div class="title">
|
1343
|
+
<a name="M000028"></a><b>inspect</b>(include_children=0)
|
1344
|
+
</div>
|
1345
|
+
<div class="description">
|
1346
|
+
<p>
|
1347
|
+
Convert to a well-formatted <a href="XML.html">XML</a>, but without <a
|
1348
|
+
href="XML.html#M000050">children</a> information. This is a reasonable
|
1349
|
+
format for irb and debugging. If you want to see a few levels of <a
|
1350
|
+
href="XML.html#M000050">children</a>, call <a
|
1351
|
+
href="XML.html#M000028">inspect</a>(2) and so on
|
1352
|
+
</p>
|
1353
|
+
</div>
|
1354
|
+
<div class="sourcecode">
|
1355
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000028_source')" id="l_M000028_source">show source</a> ]</p>
|
1356
|
+
<div id="M000028_source" class="dyn-source">
|
1357
|
+
<pre>
|
1358
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 806</span>
|
1359
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">inspect</span>(<span class="ruby-identifier">include_children</span>=<span class="ruby-value">0</span>)
|
1360
|
+
<span class="ruby-node">"<#{@name}"</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@attrs</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-node">" #{k}='#{v.xml_attr_escape}'"</span>}.<span class="ruby-identifier">join</span> <span class="ruby-operator">+</span>
|
1361
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
1362
|
+
<span class="ruby-value str">"/>"</span>
|
1363
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">include_children</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
1364
|
+
<span class="ruby-node">">...</#{name}>"</span>
|
1365
|
+
<span class="ruby-keyword kw">else</span>
|
1366
|
+
<span class="ruby-value str">">"</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">xml_escape</span> <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">inspect</span>(<span class="ruby-identifier">include_children</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>) <span class="ruby-keyword kw">end</span>}.<span class="ruby-identifier">join</span> <span class="ruby-operator">+</span> <span class="ruby-node">"</#{name}>"</span>
|
1367
|
+
<span class="ruby-keyword kw">end</span>
|
1368
|
+
<span class="ruby-keyword kw">end</span>
|
1369
|
+
</pre>
|
1370
|
+
</div>
|
1371
|
+
</div>
|
1372
|
+
</div>
|
1373
|
+
<div class="method">
|
1374
|
+
<div class="title">
|
1375
|
+
<a name="M000053"></a><b>map</b>(pat=nil) {|c| ...}
|
1376
|
+
</div>
|
1377
|
+
<div class="description">
|
1378
|
+
<p>
|
1379
|
+
FIXME: do we want a shallow or a deep copy here ? Map <a
|
1380
|
+
href="XML.html#M000050">children</a>, but leave the name/attributes
|
1381
|
+
</p>
|
1382
|
+
</div>
|
1383
|
+
<div class="sourcecode">
|
1384
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000053_source')" id="l_M000053_source">show source</a> ]</p>
|
1385
|
+
<div id="M000053_source" class="dyn-source">
|
1386
|
+
<pre>
|
1387
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1287</span>
|
1388
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">map</span>(<span class="ruby-identifier">pat</span>=<span class="ruby-keyword kw">nil</span>)
|
1389
|
+
<span class="ruby-identifier">r</span> = <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">attrs</span>)
|
1390
|
+
<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1391
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">pat</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">pat</span>
|
1392
|
+
<span class="ruby-identifier">r</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">c</span>)
|
1393
|
+
<span class="ruby-keyword kw">else</span>
|
1394
|
+
<span class="ruby-identifier">r</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>
|
1395
|
+
<span class="ruby-keyword kw">end</span>
|
1396
|
+
}
|
1397
|
+
<span class="ruby-identifier">r</span>
|
1398
|
+
<span class="ruby-keyword kw">end</span>
|
1399
|
+
</pre>
|
1400
|
+
</div>
|
1401
|
+
</div>
|
1402
|
+
</div>
|
1403
|
+
<div class="method">
|
1404
|
+
<div class="title">
|
1405
|
+
<a name="M000033"></a><b>method_missing</b>(meth, *args, &blk)
|
1406
|
+
</div>
|
1407
|
+
<div class="description">
|
1408
|
+
<p>
|
1409
|
+
Define all foo!-methods for monadic interface, so you can write:
|
1410
|
+
</p>
|
1411
|
+
</div>
|
1412
|
+
<div class="sourcecode">
|
1413
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000033_source')" id="l_M000033_source">show source</a> ]</p>
|
1414
|
+
<div id="M000033_source" class="dyn-source">
|
1415
|
+
<pre>
|
1416
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 953</span>
|
1417
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">meth</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1418
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">meth</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^(.*)!$/</span>
|
1419
|
+
<span class="ruby-keyword kw">self</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1420
|
+
<span class="ruby-keyword kw">else</span>
|
1421
|
+
<span class="ruby-identifier">real_method_missing</span>(<span class="ruby-identifier">meth</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1422
|
+
<span class="ruby-keyword kw">end</span>
|
1423
|
+
<span class="ruby-keyword kw">end</span>
|
1424
|
+
</pre>
|
1425
|
+
</div>
|
1426
|
+
</div>
|
1427
|
+
</div>
|
1428
|
+
<div class="method">
|
1429
|
+
<div class="title">
|
1430
|
+
<a name="M000046"></a><b>normalize!</b>()
|
1431
|
+
</div>
|
1432
|
+
<div class="description">
|
1433
|
+
<p>
|
1434
|
+
Normalization means joining strings and getting rid of ""s,
|
1435
|
+
recursively
|
1436
|
+
</p>
|
1437
|
+
</div>
|
1438
|
+
<div class="sourcecode">
|
1439
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000046_source')" id="l_M000046_source">show source</a> ]</p>
|
1440
|
+
<div id="M000046_source" class="dyn-source">
|
1441
|
+
<pre>
|
1442
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1171</span>
|
1443
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">normalize!</span>
|
1444
|
+
<span class="ruby-identifier">new_contents</span> = []
|
1445
|
+
<span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1446
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
1447
|
+
<span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">==</span> <span class="ruby-value str">""</span>
|
1448
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_contents</span>[<span class="ruby-value">-1</span>].<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
1449
|
+
<span class="ruby-identifier">new_contents</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>
|
1450
|
+
<span class="ruby-keyword kw">next</span>
|
1451
|
+
<span class="ruby-keyword kw">end</span>
|
1452
|
+
<span class="ruby-keyword kw">else</span>
|
1453
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">normalize!</span>
|
1454
|
+
<span class="ruby-keyword kw">end</span>
|
1455
|
+
<span class="ruby-identifier">new_contents</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">c</span>
|
1456
|
+
}
|
1457
|
+
<span class="ruby-ivar">@contents</span> = <span class="ruby-identifier">new_contents</span>
|
1458
|
+
<span class="ruby-keyword kw">end</span>
|
1459
|
+
</pre>
|
1460
|
+
</div>
|
1461
|
+
</div>
|
1462
|
+
</div>
|
1463
|
+
<div class="method">
|
1464
|
+
<div class="title">
|
1465
|
+
<a name="M000035"></a><b>range</b>(range_start, range_end, end_reached_cb=nil)
|
1466
|
+
</div>
|
1467
|
+
<div class="description">
|
1468
|
+
<p>
|
1469
|
+
Select a subtree NOTE: Uses object_id of the start/end tags ! They have to
|
1470
|
+
be the same, not just identical !
|
1471
|
+
<foo>0<a>1</a><b/><c/><d>2</d><e/>3</foo>.<a
|
1472
|
+
href="XML.html#M000035">range</a>(<a>1</a>,
|
1473
|
+
<d>2</d>) returns <foo><b/><c/></foo>
|
1474
|
+
start and end and their <a href="XML.html#M000051">descendants</a> are not
|
1475
|
+
included in the result tree. Either start or end can be nil.
|
1476
|
+
</p>
|
1477
|
+
<ul>
|
1478
|
+
<li>If both start and end are nil, return whole tree.
|
1479
|
+
|
1480
|
+
</li>
|
1481
|
+
<li>If start is nil, return subtree up to range_end.
|
1482
|
+
|
1483
|
+
</li>
|
1484
|
+
<li>If start is not inside the tree, return nil.
|
1485
|
+
|
1486
|
+
</li>
|
1487
|
+
<li>If end is nil, return subtree from start
|
1488
|
+
|
1489
|
+
</li>
|
1490
|
+
<li>If end is not inside the tree, return subtree from start.
|
1491
|
+
|
1492
|
+
</li>
|
1493
|
+
<li>If end is before or below start, or they‘re the same node, the result
|
1494
|
+
is unspecified.
|
1495
|
+
|
1496
|
+
</li>
|
1497
|
+
<li>if end comes directly after start, or as first node when start==nil, return
|
1498
|
+
path reaching there.
|
1499
|
+
|
1500
|
+
</li>
|
1501
|
+
</ul>
|
1502
|
+
</div>
|
1503
|
+
<div class="sourcecode">
|
1504
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000035_source')" id="l_M000035_source">show source</a> ]</p>
|
1505
|
+
<div id="M000035_source" class="dyn-source">
|
1506
|
+
<pre>
|
1507
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 985</span>
|
1508
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">range</span>(<span class="ruby-identifier">range_start</span>, <span class="ruby-identifier">range_end</span>, <span class="ruby-identifier">end_reached_cb</span>=<span class="ruby-keyword kw">nil</span>)
|
1509
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">range_start</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
|
1510
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">attrs</span>)
|
1511
|
+
<span class="ruby-keyword kw">else</span>
|
1512
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">nil</span>
|
1513
|
+
<span class="ruby-keyword kw">end</span>
|
1514
|
+
<span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1515
|
+
<span class="ruby-comment cmt"># end reached !</span>
|
1516
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">range_end</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">range_end</span>.<span class="ruby-identifier">object_id</span>
|
1517
|
+
<span class="ruby-identifier">end_reached_cb</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">end_reached_cb</span>
|
1518
|
+
<span class="ruby-keyword kw">break</span>
|
1519
|
+
<span class="ruby-keyword kw">end</span>
|
1520
|
+
<span class="ruby-comment cmt"># start reached !</span>
|
1521
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">range_start</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">range_start</span>.<span class="ruby-identifier">object_id</span>
|
1522
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">attrs</span>)
|
1523
|
+
<span class="ruby-keyword kw">next</span>
|
1524
|
+
<span class="ruby-keyword kw">end</span>
|
1525
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span> <span class="ruby-comment cmt"># We already started</span>
|
1526
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1527
|
+
<span class="ruby-identifier">break_me</span> = <span class="ruby-keyword kw">false</span>
|
1528
|
+
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">add!</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">range</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">range_end</span>, <span class="ruby-identifier">lambda</span>{ <span class="ruby-identifier">break_me</span> = <span class="ruby-keyword kw">true</span> })
|
1529
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">break_me</span>
|
1530
|
+
<span class="ruby-identifier">end_reached_cb</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">end_reached_cb</span>
|
1531
|
+
<span class="ruby-keyword kw">break</span>
|
1532
|
+
<span class="ruby-keyword kw">end</span>
|
1533
|
+
<span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># String/XML_PI/XML_Comment</span>
|
1534
|
+
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">add!</span> <span class="ruby-identifier">c</span>
|
1535
|
+
<span class="ruby-keyword kw">end</span>
|
1536
|
+
<span class="ruby-keyword kw">else</span>
|
1537
|
+
<span class="ruby-comment cmt"># Strings/XML_PI/XML_Comment obviously cannot start a range</span>
|
1538
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1539
|
+
<span class="ruby-identifier">break_me</span> = <span class="ruby-keyword kw">false</span>
|
1540
|
+
<span class="ruby-identifier">r</span> = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">range</span>(<span class="ruby-identifier">range_start</span>, <span class="ruby-identifier">range_end</span>, <span class="ruby-identifier">lambda</span>{ <span class="ruby-identifier">break_me</span> = <span class="ruby-keyword kw">true</span> })
|
1541
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span>
|
1542
|
+
<span class="ruby-comment cmt"># start reached !</span>
|
1543
|
+
<span class="ruby-identifier">result</span> = <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">r</span>)
|
1544
|
+
<span class="ruby-keyword kw">end</span>
|
1545
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">break_me</span>
|
1546
|
+
<span class="ruby-comment cmt"># end reached !</span>
|
1547
|
+
<span class="ruby-identifier">end_reached_cb</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">end_reached_cb</span>
|
1548
|
+
<span class="ruby-keyword kw">break</span>
|
1549
|
+
<span class="ruby-keyword kw">end</span>
|
1550
|
+
<span class="ruby-keyword kw">end</span>
|
1551
|
+
<span class="ruby-keyword kw">end</span>
|
1552
|
+
}
|
1553
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
|
1554
|
+
<span class="ruby-keyword kw">end</span>
|
1555
|
+
</pre>
|
1556
|
+
</div>
|
1557
|
+
</div>
|
1558
|
+
</div>
|
1559
|
+
<div class="method">
|
1560
|
+
<div class="title">
|
1561
|
+
<a name="M000038"></a><b>remove_pretty_printing!</b>(exceptions=nil)
|
1562
|
+
</div>
|
1563
|
+
<div class="description">
|
1564
|
+
<p>
|
1565
|
+
Get rid of pretty-printing whitespace. Also normalizes the <a
|
1566
|
+
href="XML.html">XML</a>.
|
1567
|
+
</p>
|
1568
|
+
</div>
|
1569
|
+
<div class="sourcecode">
|
1570
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000038_source')" id="l_M000038_source">show source</a> ]</p>
|
1571
|
+
<div id="M000038_source" class="dyn-source">
|
1572
|
+
<pre>
|
1573
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1096</span>
|
1574
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove_pretty_printing!</span>(<span class="ruby-identifier">exceptions</span>=<span class="ruby-keyword kw">nil</span>)
|
1575
|
+
<span class="ruby-identifier">normalize!</span>
|
1576
|
+
<span class="ruby-identifier">real_remove_pretty_printing!</span>(<span class="ruby-identifier">exceptions</span>)
|
1577
|
+
<span class="ruby-identifier">normalize!</span>
|
1578
|
+
<span class="ruby-keyword kw">end</span>
|
1579
|
+
</pre>
|
1580
|
+
</div>
|
1581
|
+
</div>
|
1582
|
+
</div>
|
1583
|
+
<div class="method">
|
1584
|
+
<div class="title">
|
1585
|
+
<a name="M000015"></a><b>sort</b>(*args, &blk)
|
1586
|
+
</div>
|
1587
|
+
<div class="description">
|
1588
|
+
<p>
|
1589
|
+
Sort <a href="XML.html#M000050">children</a> of <a href="XML.html">XML</a>
|
1590
|
+
element.
|
1591
|
+
</p>
|
1592
|
+
<p>
|
1593
|
+
Using <a href="XML.html#M000015">sort</a> is highly wrong, as <a
|
1594
|
+
href="XML.html">XML</a> (and <a href="XML.html">XML</a>-extras) is not even
|
1595
|
+
Comparable. Use <a href="XML.html#M000013">sort_by</a> instead.
|
1596
|
+
</p>
|
1597
|
+
<p>
|
1598
|
+
Unless you define your own <a href="XML.html">XML</a>#<=> operator,
|
1599
|
+
or do something equally weird.
|
1600
|
+
</p>
|
1601
|
+
</div>
|
1602
|
+
<div class="sourcecode">
|
1603
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000015_source')" id="l_M000015_source">show source</a> ]</p>
|
1604
|
+
<div id="M000015_source" class="dyn-source">
|
1605
|
+
<pre>
|
1606
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 401</span>
|
1607
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sort</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1608
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>{ <span class="ruby-ivar">@contents</span> = <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">sort</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>) }
|
1609
|
+
<span class="ruby-keyword kw">end</span>
|
1610
|
+
</pre>
|
1611
|
+
</div>
|
1612
|
+
</div>
|
1613
|
+
</div>
|
1614
|
+
<div class="method">
|
1615
|
+
<div class="title">
|
1616
|
+
<a name="M000013"></a><b>sort_by</b>(*args, &blk)
|
1617
|
+
</div>
|
1618
|
+
<div class="description">
|
1619
|
+
<p>
|
1620
|
+
Sort <a href="XML.html">XML</a> <a href="XML.html#M000050">children</a> of
|
1621
|
+
<a href="XML.html">XML</a> element.
|
1622
|
+
</p>
|
1623
|
+
</div>
|
1624
|
+
<div class="sourcecode">
|
1625
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000013_source')" id="l_M000013_source">show source</a> ]</p>
|
1626
|
+
<div id="M000013_source" class="dyn-source">
|
1627
|
+
<pre>
|
1628
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 386</span>
|
1629
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1630
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>{ <span class="ruby-ivar">@contents</span> = <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>}.<span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>) }
|
1631
|
+
<span class="ruby-keyword kw">end</span>
|
1632
|
+
</pre>
|
1633
|
+
</div>
|
1634
|
+
</div>
|
1635
|
+
</div>
|
1636
|
+
<div class="method">
|
1637
|
+
<div class="title">
|
1638
|
+
<a name="M000036"></a><b>subsequence</b>(range_start, range_end, start_seen_cb=nil, end_seen_cb=nil)
|
1639
|
+
</div>
|
1640
|
+
<div class="description">
|
1641
|
+
<p>
|
1642
|
+
<a href="XML.html#M000036">XML#subsequence</a> is similar to <a
|
1643
|
+
href="XML.html#M000035">XML#range</a>, but instead of trimmed subtree in
|
1644
|
+
returns a list of elements The same elements are included in both cases,
|
1645
|
+
but here we do not include any parents !
|
1646
|
+
</p>
|
1647
|
+
<p>
|
1648
|
+
<foo><a/><b/><c/></foo>.<a
|
1649
|
+
href="XML.html#M000035">range</a>(a,c) =>
|
1650
|
+
<foo><b/></foo>
|
1651
|
+
<foo><a/><b/><c/></foo>.<a
|
1652
|
+
href="XML.html#M000036">subsequence</a>(a,c) => <b/>
|
1653
|
+
</p>
|
1654
|
+
<p>
|
1655
|
+
<foo><a><a1/></a><b/><c/></foo>.<a
|
1656
|
+
href="XML.html#M000035">range</a>(a1,c) =>
|
1657
|
+
<foo><a/><b/></foo> # Does <a/> make sense ?
|
1658
|
+
<foo><a><a1/></a><b/><c/></foo>.<a
|
1659
|
+
href="XML.html#M000036">subsequence</a>(a1,c) => <b/>
|
1660
|
+
</p>
|
1661
|
+
<p>
|
1662
|
+
<foo><a><a1/><a2/></a><b/><c/></foo>.<a
|
1663
|
+
href="XML.html#M000035">range</a>(a1,c) =>
|
1664
|
+
<foo><a><a2/></a><b/></foo>
|
1665
|
+
<foo><a><a1/><a2/></a><b/><c/></foo>.<a
|
1666
|
+
href="XML.html#M000036">subsequence</a>(a1,c) => <a2/><b/>
|
1667
|
+
</p>
|
1668
|
+
<p>
|
1669
|
+
And we return [], not nil if nothing matches
|
1670
|
+
</p>
|
1671
|
+
</div>
|
1672
|
+
<div class="sourcecode">
|
1673
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000036_source')" id="l_M000036_source">show source</a> ]</p>
|
1674
|
+
<div id="M000036_source" class="dyn-source">
|
1675
|
+
<pre>
|
1676
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1048</span>
|
1677
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">subsequence</span>(<span class="ruby-identifier">range_start</span>, <span class="ruby-identifier">range_end</span>, <span class="ruby-identifier">start_seen_cb</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">end_seen_cb</span>=<span class="ruby-keyword kw">nil</span>)
|
1678
|
+
<span class="ruby-identifier">result</span> = []
|
1679
|
+
<span class="ruby-identifier">start_seen</span> = <span class="ruby-identifier">range_start</span>.<span class="ruby-identifier">nil?</span>
|
1680
|
+
<span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1681
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">range_end</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">range_end</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">object_id</span>
|
1682
|
+
<span class="ruby-identifier">end_seen_cb</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">end_seen_cb</span>
|
1683
|
+
<span class="ruby-keyword kw">break</span>
|
1684
|
+
<span class="ruby-keyword kw">end</span>
|
1685
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">range_start</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">range_start</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">object_id</span>
|
1686
|
+
<span class="ruby-identifier">start_seen</span> = <span class="ruby-keyword kw">true</span>
|
1687
|
+
<span class="ruby-identifier">start_seen_cb</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">start_seen_cb</span>
|
1688
|
+
<span class="ruby-keyword kw">next</span>
|
1689
|
+
<span class="ruby-keyword kw">end</span>
|
1690
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">start_seen</span>
|
1691
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1692
|
+
<span class="ruby-identifier">break_me</span> = <span class="ruby-keyword kw">false</span>
|
1693
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">subsequence</span>(<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">range_end</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">lambda</span>{<span class="ruby-identifier">break_me</span>=<span class="ruby-keyword kw">true</span>})
|
1694
|
+
<span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">break_me</span>
|
1695
|
+
<span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt"># String/XML_PI/XML_Comment</span>
|
1696
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>
|
1697
|
+
<span class="ruby-keyword kw">end</span>
|
1698
|
+
<span class="ruby-keyword kw">else</span>
|
1699
|
+
<span class="ruby-comment cmt"># String/XML_PI/XML_Comment cannot start a subsequence</span>
|
1700
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1701
|
+
<span class="ruby-identifier">break_me</span> = <span class="ruby-keyword kw">false</span>
|
1702
|
+
<span class="ruby-identifier">result</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">subsequence</span>(<span class="ruby-identifier">range_start</span>, <span class="ruby-identifier">range_end</span>, <span class="ruby-identifier">lambda</span>{<span class="ruby-identifier">start_seen</span>=<span class="ruby-keyword kw">true</span>}, <span class="ruby-identifier">lambda</span>{<span class="ruby-identifier">break_me</span>=<span class="ruby-keyword kw">true</span>})
|
1703
|
+
<span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">break_me</span>
|
1704
|
+
<span class="ruby-keyword kw">end</span>
|
1705
|
+
<span class="ruby-keyword kw">end</span>
|
1706
|
+
}
|
1707
|
+
<span class="ruby-comment cmt"># Include starting tag if it was right from the range_start</span>
|
1708
|
+
<span class="ruby-comment cmt"># Otherwise, return just the raw sequence</span>
|
1709
|
+
<span class="ruby-identifier">result</span> = [<span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@name</span>, <span class="ruby-ivar">@attrs</span>, <span class="ruby-identifier">result</span>)] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">range_start</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
|
1710
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>
|
1711
|
+
<span class="ruby-keyword kw">end</span>
|
1712
|
+
</pre>
|
1713
|
+
</div>
|
1714
|
+
</div>
|
1715
|
+
</div>
|
1716
|
+
<div class="method">
|
1717
|
+
<div class="title">
|
1718
|
+
<a name="M000047"></a><b>text</b>()
|
1719
|
+
</div>
|
1720
|
+
<div class="description">
|
1721
|
+
<p>
|
1722
|
+
Return <a href="XML.html#M000047">text</a> below the node, stripping all <a
|
1723
|
+
href="XML.html">XML</a> tags, "<foo>Hello,
|
1724
|
+
<bar>world</bar>!</foo>".xml_parse.text returns
|
1725
|
+
"Hello, world!"
|
1726
|
+
</p>
|
1727
|
+
</div>
|
1728
|
+
<div class="sourcecode">
|
1729
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000047_source')" id="l_M000047_source">show source</a> ]</p>
|
1730
|
+
<div id="M000047_source" class="dyn-source">
|
1731
|
+
<pre>
|
1732
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1191</span>
|
1733
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">text</span>
|
1734
|
+
<span class="ruby-identifier">res</span> = <span class="ruby-value str">""</span>
|
1735
|
+
<span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1736
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1737
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">text</span>
|
1738
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
1739
|
+
<span class="ruby-identifier">res</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">c</span>
|
1740
|
+
<span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># Ignore XML_PI/XML_Comment</span>
|
1741
|
+
}
|
1742
|
+
<span class="ruby-identifier">res</span>
|
1743
|
+
<span class="ruby-keyword kw">end</span>
|
1744
|
+
</pre>
|
1745
|
+
</div>
|
1746
|
+
</div>
|
1747
|
+
</div>
|
1748
|
+
<div class="method">
|
1749
|
+
<div class="title">
|
1750
|
+
<a name="M000043"></a><b>text!</b>(*args)
|
1751
|
+
</div>
|
1752
|
+
<div class="description">
|
1753
|
+
<p>
|
1754
|
+
Add some <a href="String.html">String</a> <a
|
1755
|
+
href="XML.html#M000050">children</a> (all attributes get <a
|
1756
|
+
href="XML.html#M000027">to_s</a>‘ed)
|
1757
|
+
</p>
|
1758
|
+
</div>
|
1759
|
+
<div class="sourcecode">
|
1760
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000043_source')" id="l_M000043_source">show source</a> ]</p>
|
1761
|
+
<div id="M000043_source" class="dyn-source">
|
1762
|
+
<pre>
|
1763
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1159</span>
|
1764
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">text!</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
1765
|
+
<span class="ruby-identifier">args</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">to_s</span>}
|
1766
|
+
<span class="ruby-keyword kw">end</span>
|
1767
|
+
</pre>
|
1768
|
+
</div>
|
1769
|
+
</div>
|
1770
|
+
</div>
|
1771
|
+
<div class="method">
|
1772
|
+
<div class="title">
|
1773
|
+
<a name="M000027"></a><b>to_s</b>()
|
1774
|
+
</div>
|
1775
|
+
<div class="description">
|
1776
|
+
<p>
|
1777
|
+
Convert to a well-formatted <a href="XML.html">XML</a>
|
1778
|
+
</p>
|
1779
|
+
</div>
|
1780
|
+
<div class="sourcecode">
|
1781
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000027_source')" id="l_M000027_source">show source</a> ]</p>
|
1782
|
+
<div id="M000027_source" class="dyn-source">
|
1783
|
+
<pre>
|
1784
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 794</span>
|
1785
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
|
1786
|
+
<span class="ruby-node">"<#{@name}"</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@attrs</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-node">" #{k}='#{v.xml_attr_escape}'"</span>}.<span class="ruby-identifier">join</span> <span class="ruby-operator">+</span>
|
1787
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
|
1788
|
+
<span class="ruby-value str">"/>"</span>
|
1789
|
+
<span class="ruby-keyword kw">else</span>
|
1790
|
+
<span class="ruby-value str">">"</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">xml_escape</span> <span class="ruby-keyword kw">else</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">end</span>}.<span class="ruby-identifier">join</span> <span class="ruby-operator">+</span> <span class="ruby-node">"</#{name}>"</span>
|
1791
|
+
<span class="ruby-keyword kw">end</span>
|
1792
|
+
<span class="ruby-keyword kw">end</span>
|
1793
|
+
</pre>
|
1794
|
+
</div>
|
1795
|
+
</div>
|
1796
|
+
</div>
|
1797
|
+
<div class="method">
|
1798
|
+
<div class="title">
|
1799
|
+
<a name="M000044"></a><b>xml!</b>(*args, &blk)
|
1800
|
+
</div>
|
1801
|
+
<div class="description">
|
1802
|
+
<p>
|
1803
|
+
Add <a href="XML.html">XML</a> <a href="XML.html#M000048">child</a>
|
1804
|
+
</p>
|
1805
|
+
</div>
|
1806
|
+
<div class="sourcecode">
|
1807
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000044_source')" id="l_M000044_source">show source</a> ]</p>
|
1808
|
+
<div id="M000044_source" class="dyn-source">
|
1809
|
+
<pre>
|
1810
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1163</span>
|
1811
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xml!</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1812
|
+
<span class="ruby-ivar">@contents</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">XML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
1813
|
+
<span class="ruby-keyword kw">end</span>
|
1814
|
+
</pre>
|
1815
|
+
</div>
|
1816
|
+
</div>
|
1817
|
+
</div>
|
1818
|
+
<div class="sectiontitle">Protected Instance methods</div>
|
1819
|
+
<div class="method">
|
1820
|
+
<div class="title">
|
1821
|
+
<a name="M000041"></a><b>real_add_pretty_printing!</b>(indent = "")
|
1822
|
+
</div>
|
1823
|
+
<div class="sourcecode">
|
1824
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000041_source')" id="l_M000041_source">show source</a> ]</p>
|
1825
|
+
<div id="M000041_source" class="dyn-source">
|
1826
|
+
<pre>
|
1827
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1127</span>
|
1828
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">real_add_pretty_printing!</span>(<span class="ruby-identifier">indent</span> = <span class="ruby-value str">""</span>)
|
1829
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">empty?</span>
|
1830
|
+
<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1831
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML</span>
|
1832
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">real_add_pretty_printing!</span>(<span class="ruby-identifier">indent</span><span class="ruby-operator">+</span><span class="ruby-value str">" "</span>)
|
1833
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
1834
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\n\s*/</span>, <span class="ruby-node">"\n#{indent} "</span>)
|
1835
|
+
<span class="ruby-keyword kw">end</span>
|
1836
|
+
}
|
1837
|
+
<span class="ruby-ivar">@contents</span> = <span class="ruby-ivar">@contents</span>.<span class="ruby-identifier">inject</span>([]){<span class="ruby-operator">|</span><span class="ruby-identifier">children</span>, <span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">children</span> <span class="ruby-operator">+</span> [<span class="ruby-node">"\n#{indent} "</span>, <span class="ruby-identifier">c</span>]}<span class="ruby-operator">+</span>[<span class="ruby-node">"\n#{indent}"</span>]
|
1838
|
+
<span class="ruby-keyword kw">end</span>
|
1839
|
+
</pre>
|
1840
|
+
</div>
|
1841
|
+
</div>
|
1842
|
+
</div>
|
1843
|
+
<div class="method">
|
1844
|
+
<div class="title">
|
1845
|
+
<a name="M000039"></a><b>real_remove_pretty_printing!</b>(exceptions=nil)
|
1846
|
+
</div>
|
1847
|
+
<div class="description">
|
1848
|
+
<p>
|
1849
|
+
<a href="XML.html#M000046">normalize!</a> is already recursive, so only one
|
1850
|
+
call at top level is needed. This helper method lets us avoid extra calls
|
1851
|
+
to <a href="XML.html#M000046">normalize!</a>.
|
1852
|
+
</p>
|
1853
|
+
</div>
|
1854
|
+
<div class="sourcecode">
|
1855
|
+
<p class="source-link">[ <a href="javascript:toggleSource('M000039_source')" id="l_M000039_source">show source</a> ]</p>
|
1856
|
+
<div id="M000039_source" class="dyn-source">
|
1857
|
+
<pre>
|
1858
|
+
<span class="ruby-comment cmt"># File magic_xml.rb, line 1104</span>
|
1859
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">real_remove_pretty_printing!</span>(<span class="ruby-identifier">exceptions</span>=<span class="ruby-keyword kw">nil</span>)
|
1860
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exceptions</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">exceptions</span>.<span class="ruby-identifier">include?</span> <span class="ruby-ivar">@name</span>
|
1861
|
+
<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
|
1862
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
1863
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp re">/^\s+/</span>, <span class="ruby-value str">""</span>)
|
1864
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp re">/\s+$/</span>, <span class="ruby-value str">""</span>)
|
1865
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/\s+/</span>, <span class="ruby-value str">" "</span>)
|
1866
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML_PI</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">XML_Comment</span>
|
1867
|
+
<span class="ruby-keyword kw">else</span>
|
1868
|
+
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">real_remove_pretty_printing!</span>(<span class="ruby-identifier">exceptions</span>)
|
1869
|
+
<span class="ruby-keyword kw">end</span>
|
1870
|
+
}
|
1871
|
+
<span class="ruby-keyword kw">end</span>
|
1872
|
+
</pre>
|
1873
|
+
</div>
|
1874
|
+
</div>
|
1875
|
+
</div>
|
1876
|
+
</div>
|
1877
|
+
|
1878
|
+
</div>
|
1879
|
+
|
1880
|
+
</body>
|
1881
|
+
</html>
|