4 # FILE: SPT--XMLStream.php
7 # XMLStream($StartingIndentLevel = 0, $IndentSize = 4)
9 # AddElement($Name = NULL, $Content = NULL, $Attributes = NULL)
10 # - add element (i.e. tag) to XML stream
11 # OpenElement($Name, $Attributes = NULL)
12 # - open new element in XML stream
14 # - close current element in XML stream
16 # - return current stream content
18 # - clear current stream content
19 # IndentLevel($NewIndentLevel = NULL)
20 # - get/set current indent level
21 # IndentSize($NewIndentSize = NULL)
22 # - get/set current indent size
24 # AUTHOR: Edward Almasy
26 # Part of the Scout Portal Toolkit
27 # Copyright 2003-2004 Internet Scout Project
28 # http://scout.wisc.edu
33 # ---- PUBLIC INTERFACE --------------------------------------------------
36 function XMLStream($StartingIndentLevel = 0, $IndentSize = 4)
38 # initialize stack used to track open elements
39 $this->OpenTagStack = array();
41 # initialize current stream content
42 $this->Stream =
"<?xml version=\"1.0\"?>\n";
44 # initialize current indent level and size
45 $this->CurrentIndentLevel = $StartingIndentLevel;
46 $this->CurrentIndentSize = $IndentSize;
49 # add element (i.e. tag) to XML stream
52 # if tag name supplied
55 # start out with appropriate indent
56 $Tag = str_repeat(
" ", ($this->CurrentIndentLevel * $this->CurrentIndentSize));
61 # if attributes supplied
65 foreach ($Attributes as $AttributeName => $AttributeValue)
67 $Tag .=
" ".$AttributeName.
"=\"".$AttributeValue.
"\"";
71 # if content supplied or we are assuming tag content
78 if ($Content !== NULL)
80 $Tag .= htmlspecialchars($Content);
84 $Tag .=
"</".$Name.
">\n";
91 # increase indent level
92 $this->CurrentIndentLevel++;
94 # add tag to open tag stack
95 array_push($this->OpenTagStack, $Name);
100 # decrease indent level
101 if ($this->CurrentIndentLevel > 0) { $this->CurrentIndentLevel--; }
103 # pop last entry off of open tag stack
104 $LastName = array_pop($this->OpenTagStack);
106 # start out with appropriate indent
107 $Tag = str_repeat(
" ", ($this->CurrentIndentLevel * $this->CurrentIndentSize));
109 # add end tag to match last open tag
110 $Tag .=
"</".$LastName.
">\n";
113 # add formatted tag to stream
114 $this->Stream .= $Tag;
117 # open new element in XML stream
123 # close current element in XML stream
129 # return current stream content
135 # clear current stream content
141 # get/set current indent level
144 # if new indent level supplied
145 if ($NewIndentLevel !== NULL)
147 # reset indent to requested level
148 $this->CurrentIndentLevel = $NewIndentLevel;
151 # return current indent level to caller
155 # get/set current indent size
158 # if new indent size supplied
159 if ($NewIndentSize !== NULL)
161 # reset indent to requested size
162 $this->CurrentIndentSize = $NewIndentSize;
165 # return current indent size to caller
170 # ---- PRIVATE INTERFACE -------------------------------------------------
178 define(
"SCOUTXMLSTREAMNULLVALUE",
"X-SCOUT_XML_STREAM_NULL_VALUE-X");
IndentLevel($NewIndentLevel=NULL)
OpenElement($Name, $Attributes=SCOUTXMLSTREAMNULLVALUE)
IndentSize($NewIndentSize=NULL)
XMLStream($StartingIndentLevel=0, $IndentSize=4)
const SCOUTXMLSTREAMNULLVALUE
AddElement($Name=SCOUTXMLSTREAMNULLVALUE, $Content=SCOUTXMLSTREAMNULLVALUE, $Attributes=SCOUTXMLSTREAMNULLVALUE)