/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/tag_utils/xml_utils.inc
ViewVC logotype

Contents of /nfo/php/libs/com.newsblob.phphtmllib/tag_utils/xml_utils.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sat Sep 20 00:15:57 2003 UTC (20 years, 11 months ago) by jonen
Branch: MAIN
Changes since 1.2: +22 -2 lines
+ updated whole phphtmllib to v2.3.0

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.7 2003/07/31 23:06:56 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 * @param string - the xml tag name
22 * @param array - the name="value" pairs of
23 * tag attributes
24 * @param mixed - any content that lives in the
25 * PCDATA portion of the XML tag
26 *
27 * @return XMLTagClass object
28 */
29 function &xml_tag($name, $attributes=array()) {
30 $tag = new XMLTagClass($name, $attributes);
31 $num_args = func_num_args();
32 for ($i=2;$i<$num_args;$i++) {
33 $tag->add(func_get_arg($i));
34 }
35 return $tag;
36 }
37
38 /**
39 * This builds an xml tag, just as xml_tag() does,
40 * but turns on the auto wrapping of CDATA for the
41 * content for the tag.
42 *
43 * @param string - the xml tag name
44 * @param array - the name="value" pairs of
45 * tag attributes
46 * @param mixed - any content that lives in the
47 * PCDATA portion of the XML tag
48 *
49 * @return XMLTagClass object
50 */
51 function &xml_ctag($name, $attributes=array()) {
52 $args = func_get_args();
53 $tag =& call_user_func_array("xml_tag", $args);
54 $tag->set_cdata_flag(TRUE);
55 return $tag;
56 }
57
58
59 /**
60 * This function is used to build a
61 * DOCTYPE tag
62 *
63 * @param string - the document element name (ie. 'HTML')
64 * @param string - the source (ie. 'PUBLIC')
65 * @param string - link 1 (ie. '-//W3C//DTD XHTML 1.0 Transitional//EN' )
66 * @param string - link 2 (ie. 'DTD/xhtml1-transitional.dtd' )
67 *
68 * @return DOCTYPEtag object
69 */
70 function xml_doctype($doc_element, $source="PUBLIC", $link1=NULL, $link2=NULL) {
71
72 $attributes = array($doc_element, $source);
73
74 if ($link1 != NULL) {
75 array_push($attributes, "\"". $link1."\"");
76 }
77
78 if ($link2 != NULL) {
79 array_push($attributes, "\"". $link2."\"");
80 }
81
82 return new DOCTYPEtag( $attributes );
83 }
84
85 /**
86 * This function is used to build an
87 * xml-stylesheet tag
88 *
89 * @param string - the href attribute
90 * @param string - the type attribute
91 *
92 * @return XMLSTYLESHEETtag object
93 */
94 function xml_stylesheet( $href, $type="text/css" ) {
95 return new XMLSTYLESHEETtag( array("href" => $href,
96 "type" => $type));
97 }
98
99
100
101 /**
102 * This function converts an array to
103 * an xml document.
104 *
105 * @param array
106 * @param string
107 */
108 function array_to_xml_tree( $arr ) {
109
110 $xml = container();
111
112 foreach( $arr as $name => $value) {
113 if (is_array($value)) {
114 $xml->push(xml_tag($name, array(), array_to_xml_tree( $value )));
115 } else {
116 $xml->push(xml_tag( $name, array(), $value ));
117 }
118 }
119 return $xml;
120 }
121
122
123 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed