/
usr
/
share
/
doc
/
cpanel-php84-xml-serializer
/
examples
/
/usr/share/doc/cpanel-php84-xml-serializer/examples
mkdir
upload
Name
Size
Mode
Actions
example.xml
82
0644
edit
dl
rm
serializeAndEncode.php
1450
0644
edit
dl
rm
serializeAndReturn.php
609
0644
edit
dl
rm
serializeCData.php
838
0644
edit
dl
rm
serializeIndexedArray.php
2548
0644
edit
dl
rm
serializeIndexedArrayWithContext.php
1039
0644
edit
dl
rm
serializeNullProperties.php
1371
0644
edit
dl
rm
serializeObject.php
1325
0644
edit
dl
rm
serializeRDF.php
3092
0644
edit
dl
rm
Serializer_Bug7112.php
724
0644
edit
dl
rm
serializeSelectiveAttributes.php
1641
0644
edit
dl
rm
serializeWithAttributes.php
1191
0644
edit
dl
rm
serializeWithAttributes2.php
1362
0644
edit
dl
rm
serializeWithComment.php
974
0644
edit
dl
rm
serializeWithDtd.php
925
0644
edit
dl
rm
serializeWithIndentedAttributes.php
1469
0644
edit
dl
rm
serializeWithNamespace.php
1072
0644
edit
dl
rm
serializeWithTagMap.php
2766
0644
edit
dl
rm
unserializeAnyXML.php
2609
0644
edit
dl
rm
unserializeClassNames.php
1222
0644
edit
dl
rm
unserializeEncoded.php
949
0644
edit
dl
rm
unserializeEnum.php
1187
0644
edit
dl
rm
unserializeObject.php
1472
0644
edit
dl
rm
unserializeRDF.php
2130
0644
edit
dl
rm
unserializeWhitespace.php
1112
0644
edit
dl
rm
unserializeWithAttributes.php
796
0644
edit
dl
rm
unserializeWithTagMap.php
1661
0644
edit
dl
rm
unserializeWithTypeGuessing.php
950
0644
edit
dl
rm
Edit:
/usr/share/doc/cpanel-php84-xml-serializer/examples/unserializeAnyXML.php
(2609B)
<?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>'; } ?>
Save
cmd:
run