1 |
<?php |
2 |
|
3 |
/** |
4 |
* This file holds helper functions |
5 |
* for things related to XMLTagClass |
6 |
* objects/data |
7 |
* |
8 |
* $Id: xml_utils.inc,v 1.8 2004/03/31 00:58:22 hemna Exp $ |
9 |
* |
10 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
11 |
* @package phpHtmlLib |
12 |
* |
13 |
*/ |
14 |
|
15 |
|
16 |
|
17 |
/** |
18 |
* This is a simple wrapper function |
19 |
* for building XMLTagClass objects |
20 |
* |
21 |
* @tutorial XMLTagClass.cls#helper |
22 |
* |
23 |
* @param string - the xml tag name |
24 |
* @param array - the name="value" pairs of |
25 |
* tag attributes |
26 |
* @param mixed - any content that lives in the |
27 |
* PCDATA portion of the XML tag |
28 |
* |
29 |
* @return XMLTagClass object |
30 |
*/ |
31 |
function &xml_tag($name, $attributes=array()) { |
32 |
$tag = new XMLTagClass($name, $attributes); |
33 |
$num_args = func_num_args(); |
34 |
for ($i=2;$i<$num_args;$i++) { |
35 |
$tag->add(func_get_arg($i)); |
36 |
} |
37 |
return $tag; |
38 |
} |
39 |
|
40 |
/** |
41 |
* This builds an xml tag, just as xml_tag() does, |
42 |
* but turns on the auto wrapping of CDATA for the |
43 |
* content for the tag. |
44 |
* |
45 |
* @param string - the xml tag name |
46 |
* @param array - the name="value" pairs of |
47 |
* tag attributes |
48 |
* @param mixed - any content that lives in the |
49 |
* PCDATA portion of the XML tag |
50 |
* |
51 |
* @return XMLTagClass object |
52 |
*/ |
53 |
function &xml_ctag($name, $attributes=array()) { |
54 |
$args = func_get_args(); |
55 |
$tag =& call_user_func_array("xml_tag", $args); |
56 |
$tag->set_cdata_flag(TRUE); |
57 |
return $tag; |
58 |
} |
59 |
|
60 |
|
61 |
/** |
62 |
* This function is used to build a |
63 |
* DOCTYPE tag |
64 |
* |
65 |
* @param string - the document element name (ie. 'HTML') |
66 |
* @param string - the source (ie. 'PUBLIC') |
67 |
* @param string - link 1 (ie. '-//W3C//DTD XHTML 1.0 Transitional//EN' ) |
68 |
* @param string - link 2 (ie. 'DTD/xhtml1-transitional.dtd' ) |
69 |
* |
70 |
* @return DOCTYPEtag object |
71 |
*/ |
72 |
function xml_doctype($doc_element, $source="PUBLIC", $link1=NULL, $link2=NULL) { |
73 |
|
74 |
$attributes = array($doc_element, $source); |
75 |
|
76 |
if ($link1 != NULL) { |
77 |
array_push($attributes, "\"". $link1."\""); |
78 |
} |
79 |
|
80 |
if ($link2 != NULL) { |
81 |
array_push($attributes, "\"". $link2."\""); |
82 |
} |
83 |
|
84 |
return new DOCTYPEtag( $attributes ); |
85 |
} |
86 |
|
87 |
/** |
88 |
* This function is used to build an |
89 |
* xml-stylesheet tag |
90 |
* |
91 |
* @param string - the href attribute |
92 |
* @param string - the type attribute |
93 |
* |
94 |
* @return XMLSTYLESHEETtag object |
95 |
*/ |
96 |
function xml_stylesheet( $href, $type="text/css" ) { |
97 |
return new XMLSTYLESHEETtag( array("href" => $href, |
98 |
"type" => $type)); |
99 |
} |
100 |
|
101 |
|
102 |
|
103 |
/** |
104 |
* This function converts an array to |
105 |
* an xml document. |
106 |
* |
107 |
* @param array |
108 |
* @param string |
109 |
*/ |
110 |
function array_to_xml_tree( $arr ) { |
111 |
|
112 |
$xml = container(); |
113 |
|
114 |
foreach( $arr as $name => $value) { |
115 |
if (is_array($value)) { |
116 |
$xml->push(xml_tag($name, array(), array_to_xml_tree( $value ))); |
117 |
} else { |
118 |
$xml->push(xml_tag( $name, array(), $value )); |
119 |
} |
120 |
} |
121 |
return $xml; |
122 |
} |
123 |
|
124 |
|
125 |
?> |