PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / trunk
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets vtrunk
3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / classes / arraytoxml.php
wp-all-import / classes Last commit date
XmlStreamReader 3 weeks ago partner-discount-sdk 3 weeks ago api.php 3 weeks ago arraytoxml.php 3 weeks ago chunk.php 3 weeks ago config.php 2 years ago download.php 3 weeks ago error.php 3 weeks ago handler.php 3 weeks ago helper.php 3 weeks ago input.php 3 weeks ago nested.php 3 weeks ago rapidaddon.php 3 weeks ago render.php 3 weeks ago session.php 10 months ago upload.php 3 weeks ago zip.php 10 years ago
arraytoxml.php
65 lines
1 <?php
2
3 class PMXI_ArrayToXML
4 {
5 /**
6 * The main function for converting to an XML document.
7 * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
8 *
9 * @param array $data
10 * @param string $rootNodeName - what you want the root node to be - defaultsto data.
11 * @param SimpleXMLElement $xml - should only be used recursively
12 * @return string XML
13 */
14 public static function toXml($data, $rootNodeName = 'data', $xml=null, $lvl = 0)
15 {
16
17 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
18 $data = apply_filters('wp_all_import_json_to_xml', $data);
19
20 if ($xml == null)
21 {
22 $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><'.$rootNodeName .'/>');
23 }
24
25 if ( !empty($data)){
26 // loop through the data passed in.
27 foreach($data as $key => $value)
28 {
29 // no numeric keys in our xml please!
30 if (!$key or is_numeric($key))
31 {
32 // make string key...
33 $key = "item_" . $lvl;
34
35 }
36
37 // replace anything not alpha numeric
38 // preg_replace('/^[0-9]+/i', '', preg_replace('/[^a-z0-9_]/i', '', $key))
39 $key = preg_replace('/[^a-z0-9_]/i', '', $key);
40
41 if ($key && is_numeric($key[0])) $key = 'v' . $key;
42
43 // if there is another array found recrusively call this function
44 if (is_array($value) or is_object($value))
45 {
46 $node = $xml->addChild($key);
47 // recrusive call.
48 PMXI_ArrayToXML::toXml($value, $rootNodeName, $node, $lvl + 1);
49 }
50 else
51 {
52 // add single node.
53 $value = htmlspecialchars(preg_replace('/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $value));
54 $xml->addChild($key, $value);
55
56 }
57
58 }
59 }
60 // pass back as string. or simple xml object if you want!
61 return $xml->asXML();
62 }
63
64
65 }