Submit
Path:
~
/
/
usr
/
share
/
doc
/
cpanel-php81-xml-serializer-0.21.0
/
examples
/
File Content:
unserializeAnyXML.php
<?PHP /** * This example shows different methods how * XML_Unserializer can be used to create data structures * from XML documents. * * @author Stephan Schmidt <schst@php.net> */ error_reporting(E_ALL); // this is a simple XML document $xml = '<users>' . ' <user handle="schst">Stephan Schmidt</user>' . ' <user handle="mj">Martin Jansen</user>' . ' <group name="qa">PEAR QA Team</group>' . ' <foo id="test">This is handled by the default keyAttribute</foo>' . ' <foo id="test2">Another foo tag</foo>' . '</users>'; require_once 'XML/Unserializer.php'; // complex structures are arrays, the key is the attribute 'handle' or 'name', if handle is not present $options = array( XML_UNSERIALIZER_OPTION_COMPLEXTYPE => 'array', XML_UNSERIALIZER_OPTION_ATTRIBUTE_KEY => array( 'user' => 'handle', 'group' => 'name', '#default' => 'id' ) ); // be careful to always use the ampersand in front of the new operator $unserializer = &new XML_Unserializer($options); // userialize the document $status = $unserializer->unserialize($xml, false); if (PEAR::isError($status)) { echo 'Error: ' . $status->getMessage(); } else { $data = $unserializer->getUnserializedData(); echo '<pre>'; print_r($data); echo '</pre>'; } // unserialize it again and change the complexType option // but leave other options untouched // now complex types will be an object, and the property name will be in the // attribute 'handle' $status = $unserializer->unserialize($xml, false, array(XML_UNSERIALIZER_OPTION_COMPLEXTYPE => 'object')); if (PEAR::isError($status)) { echo 'Error: ' . $status->getMessage(); } else { $data = $unserializer->getUnserializedData(); echo '<pre>'; print_r($data); echo '</pre>'; } // unserialize it again and change the complexType option // and reset all other options // Now, there's no key so the tags are stored in an array $status = $unserializer->unserialize($xml, false, array(XML_UNSERIALIZER_OPTION_OVERRIDE_OPTIONS => true, XML_UNSERIALIZER_OPTION_COMPLEXTYPE => 'object')); if (PEAR::isError($status)) { echo 'Error: ' . $status->getMessage(); } else { $data = $unserializer->getUnserializedData(); echo '<pre>'; print_r($data); echo '</pre>'; } ?>
Submit
FILE
FOLDER
Name
Size
Permission
Action
Serializer_Bug7112.php
724 bytes
0644
example.xml
82 bytes
0644
serializeAndEncode.php
1450 bytes
0644
serializeAndReturn.php
609 bytes
0644
serializeCData.php
838 bytes
0644
serializeIndexedArray.php
2548 bytes
0644
serializeIndexedArrayWithContext.php
1039 bytes
0644
serializeNullProperties.php
1371 bytes
0644
serializeObject.php
1325 bytes
0644
serializeRDF.php
3092 bytes
0644
serializeSelectiveAttributes.php
1641 bytes
0644
serializeWithAttributes.php
1191 bytes
0644
serializeWithAttributes2.php
1362 bytes
0644
serializeWithComment.php
974 bytes
0644
serializeWithDtd.php
925 bytes
0644
serializeWithIndentedAttributes.php
1469 bytes
0644
serializeWithNamespace.php
1072 bytes
0644
serializeWithTagMap.php
2766 bytes
0644
unserializeAnyXML.php
2609 bytes
0644
unserializeClassNames.php
1222 bytes
0644
unserializeEncoded.php
949 bytes
0644
unserializeEnum.php
1187 bytes
0644
unserializeObject.php
1472 bytes
0644
unserializeRDF.php
2130 bytes
0644
unserializeWhitespace.php
1112 bytes
0644
unserializeWithAttributes.php
796 bytes
0644
unserializeWithTagMap.php
1661 bytes
0644
unserializeWithTypeGuessing.php
950 bytes
0644
N4ST4R_ID | Naxtarrr