Andrew's Web Libraries (AWL)
XMLElement Class Reference

Public Member Functions

 __construct ( $tagname, $content=false, $attributes=false, $xmlns=null)
 
 CountElements ()
 
 SetAttribute ($k, $v)
 
 SetContent ($v)
 
 GetTag ()
 
 GetNSTag ()
 
 GetAttribute ( $attr)
 
 GetAttributes ()
 
 GetContent ()
 
 GetElements ( $tag=null, $recursive=false)
 
 GetPath ( $path)
 
 AddSubTag (&$v)
 
NewElement ( $tagname, $content=false, $attributes=false, $xmlns=null)
 
 RenderContent ($indent=0, $nslist=null, $force_xmlns=false)
 
 Render ($indent=0, $xmldef="", $nslist=null, $force_xmlns=false)
 
 __tostring ()
 

Protected Attributes

 $tagname
 
 $xmlns
 
 $attributes
 
 $content
 
 $_parent
 

Detailed Description

Definition at line 20 of file XMLElement.php.

Constructor & Destructor Documentation

◆ __construct()

XMLElement::__construct (   $tagname,
  $content = false,
  $attributes = false,
  $xmlns = null 
)

Constructor - nothing fancy as yet.

Parameters
string$tagnameThe tag name of the new element
mixed$contentEither a string of content, or an array of sub-elements
array$attributesAn array of attribute name/value pairs
string$xmlnsAn XML namespace specifier

Definition at line 35 of file XMLElement.php.

Member Function Documentation

◆ __tostring()

XMLElement::__tostring ( )

Definition at line 335 of file XMLElement.php.

◆ AddSubTag()

XMLElement::AddSubTag ( $v)

Add a sub-element

Parameters
objectAn XMLElement to be appended to the array of sub-elements

Definition at line 216 of file XMLElement.php.

◆ CountElements()

XMLElement::CountElements ( )

Count the number of elements

Returns
int The number of elements

Definition at line 69 of file XMLElement.php.

◆ GetAttribute()

XMLElement::GetAttribute (   $attr)

Accessor for a single attribute

Parameters
string$attrThe name of the attribute.
Returns
string The value of that attribute of the element

Definition at line 122 of file XMLElement.php.

◆ GetAttributes()

XMLElement::GetAttributes ( )

Accessor for the attributes

Returns
array The attributes of this element

Definition at line 133 of file XMLElement.php.

◆ GetContent()

XMLElement::GetContent ( )

Accessor for the content

Returns
array The content of this element

Definition at line 142 of file XMLElement.php.

◆ GetElements()

XMLElement::GetElements (   $tag = null,
  $recursive = false 
)

Return an array of elements matching the specified tag, or all elements if no tag is supplied. Unlike GetContent() this will always return an array.

Returns
array The XMLElements within the tree which match this tag

Definition at line 152 of file XMLElement.php.

◆ GetNSTag()

XMLElement::GetNSTag ( )

Accessor for the full-namespaced tag name

Returns
string The tag name of the element, prefixed by the namespace

Definition at line 113 of file XMLElement.php.

◆ GetPath()

XMLElement::GetPath (   $path)

Return an array of elements matching the specified path

Returns
array The XMLElements within the tree which match this tag

That is the full path

There is more to the path, so we recurse into that sub-part

If our input $path was not rooted, we recurse further

Definition at line 176 of file XMLElement.php.

◆ GetTag()

XMLElement::GetTag ( )

Accessor for the tag name

Returns
string The tag name of the element

Definition at line 104 of file XMLElement.php.

◆ NewElement()

& XMLElement::NewElement (   $tagname,
  $content = false,
  $attributes = false,
  $xmlns = null 
)

Add a new sub-element

Parameters
stringThe tag name of the new element
mixedEither a string of content, or an array of sub-elements
arrayAn array of attribute name/value pairs
Returns
objectref A reference to the new XMLElement

Definition at line 231 of file XMLElement.php.

◆ Render()

XMLElement::Render (   $indent = 0,
  $xmldef = "",
  $nslist = null,
  $force_xmlns = false 
)

Render the document tree into (nicely formatted) XML

Parameters
intThe indenting level for the pretty formatting of the element

Render the element attribute values

Definition at line 284 of file XMLElement.php.

◆ RenderContent()

XMLElement::RenderContent (   $indent = 0,
  $nslist = null,
  $force_xmlns = false 
)

Render just the internal content

Returns
string The content of this element, as a string without this element wrapping it.

Render the sub-elements with a deeper indent level

Render the content, with special characters escaped

Definition at line 244 of file XMLElement.php.

◆ SetAttribute()

XMLElement::SetAttribute (   $k,
  $v 
)

Set an element attribute to a value

Parameters
stringThe attribute name
stringThe attribute value

Definition at line 82 of file XMLElement.php.

◆ SetContent()

XMLElement::SetContent (   $v)

Set the whole content to a value

Parameters
mixedThe element content, which may be text, or an array of sub-elements

Definition at line 95 of file XMLElement.php.

Member Data Documentation

◆ $_parent

XMLElement::$_parent
protected

Definition at line 25 of file XMLElement.php.

◆ $attributes

XMLElement::$attributes
protected

Definition at line 23 of file XMLElement.php.

◆ $content

XMLElement::$content
protected

Definition at line 24 of file XMLElement.php.

◆ $tagname

XMLElement::$tagname
protected

Definition at line 21 of file XMLElement.php.

◆ $xmlns

XMLElement::$xmlns
protected

Definition at line 22 of file XMLElement.php.


The documentation for this class was generated from the following file: