digitickets / lalit Goto Github PK
View Code? Open in Web Editor NEWA GitHub copy of the XML2Array class provided by http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/
A GitHub copy of the XML2Array class provided by http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/
1 insert in the the root node need to add parameters
examle: creat date
2 add in line 2 format description
required result
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog date="2019-01-31 17:02">
Take the XML of ...
$xml = <<< END_XML
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<content>
<!-- A comment -->
<level level="1">
<!-- A comment -->
<level level="2">
<!-- A comment -->
<level level="3">
<!-- A comment -->
<node node="1"/>
<node node="2"/>
<!-- A comment -->
<node node="3"/>
</level>
</level>
</level>
</content>
END_XML;
When processed using XML2Array::convert()
, the resulting array is ...
Array
(
[content] => Array
(
[level] => Array
(
[level] => Array
(
[level] => Array
(
[node] => Array
(
[@value] =>
[@attributes] => Array
(
[node] => 3
)
)
[@attributes] => Array
(
[level] => 3
)
)
[@attributes] => Array
(
[level] => 2
)
)
[@attributes] => Array
(
[level] => 1
)
)
)
)
What is the license for this package? It is possible to include it in the vendor with composer?
I'm fetching some data from a MySQL table via PDO, then using Array2XML to write that data to an XML file. The encoding of my MySQL database/table/column is utf8mb4
.
My problem is that some data seems to get modified by Array2XML as it's being converted to XML.
For example, in the database I have a carriage return character which appears in the XML output as
, the HTML entity encoded version of a carriage return.
Illustrative example:
<?php
// print_r($array);
[content] => "Here I have a
carriage return"
// echo $xml->saveXML();
<content>Here I have a carriage return</content>
Heya,
Awesome work by both the original author & yourself 👍
Anyway, I've found what appears to be a bug. When parsing this
array (
"hpo" => array (
"HP_0012759" => array (
"term" => "Neurodevelopmental abnormality",
"@attributes" => array (
"present" => "na"
),
"onset" => array (
"@attributes" => array (
"units" => "years"
),
"@value" => NULL
)
)
)
)
I get an exception Message: [Array2XML] Illegal character in tag name. tag: @value in node: onset
Cheers,
Algy
Hi,
I'm converting jsons to XML using your class but I often get errors like
Uncaught Exception: [Array2XML] Illegal character in tag name. tag: $schema in node: root
Is there a way to clean the keys recursively in the array before calling createXML() so that this error is not fired ? Thanks.
I'd like to create XML from array and have a few questions about array2XML features.
1.
In my case XML has to star with this node:
<dpi:DPI_OECD xmlns:dpi="urn:oecd:ties:dpi:v1" xmlns:stf="urn:oecd:ties:dpistf:v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="urn:oecd:ties:dpi:v1 ../XSD/DPIXML_v1.0.xsd">
or with SOAP signature:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
But looks like $node_name parameter of createXML method cannot be used to create such and XML.
How to solve this?
I have a multiple nodes of same name. How to handle them in an array?
Is it possible to create partial document with Array2XML and then embed it into main XML document as some child?
with xmlToArray,
if i have attributes like
<Description xml:lang="en-GB" /> Test </Description>
it gives me array like
"Description" => array:2 [ "@value" => "Test" "@attributes" => array:1 [ "lang" => "en-GB" ] ]
and the obvious ArrayToXml output:
<Description lang="en-GB" /> Test </Description>
Can you please tag 3.4.0 - commits have been merged in but no corresponding tag exists
Hello, i have found a very strange bug.
in some case the "is_numeric(key($value)" return null in php 7, but not php 5.6, ending up with an error :
[Array2XML] Illegal character in tag name. tag: 0 in node: data
The used array is (with print_r result) :
Array
(
[element] => Array
(
[0] => Array
(
[trigger_table] => messages
[action] => insert
[unicite] => 100001##ico-CpswP0E3EJPLAule1N5hc68TiYm_np3LMxmdk-O6LAe4P_vqcK
[data] => Array
(
[0] => Array
(
[icone] => ico-CpswP0E3EJPLAule1N5hc68TiYm_np3LMxmdk-O6LAe4P_vqcK
[userid] => 100001
[sujet] => sujet-SOScngEPXzcQ_MBK6dMi2Fco-GbtDGewd1lRZxajkg4Jcc1jmg
)
)
)
[1] => Array
(
[trigger_table] => messages
[action] => insert
[unicite] => 100001##ico-Y2QIAITIeorcfTONGyFfWapulT4E5B73qwCMKiEvRaAEnBOV5A
[data] => Array
(
[0] => Array
(
[icone] => ico-Y2QIAITIeorcfTONGyFfWapulT4E5B73qwCMKiEvRaAEnBOV5A
[userid] => 100001
[sujet] => sujet-NLt1uZgkKx-7_FNqCgx7UW9myPPxKDqRJeWQTjuQ6zNtR4kA36
)
)
)
)
)
I can correct the error 2 way :
Bad way :
$array_good=json_decode(json_encode($array),true);
Good but i don't know why way :
throw new Exception('[Array2XML] Illegal character in tag name. tag: '.$key.' in node: '.$node_name);
}
if (is_array($value)
&& (is_null(key($value)) || is_numeric(key($value)))) {
// MORE THAN ONE NODE OF ITS KIND;
// if the new array is numeric index, means it is array of nodes of the same kind
// it should follow the parent key name
foreach ($value as $k => $v) {
$node->appendChild(self::convert($key, $v));
}
maybe the array i generate is wrong someway, but var_dump the before / after json result as EXACTLY the same string, so i don't know how to see the difference between the 2 array
In the php7 change http://php.net/manual/en/migration70.incompatible.php
Changes to foreach ¶
Minor changes have been made to the behaviour of the foreach control structure, primarily around the handling of the internal array pointer and modification of the array being iterated over.
foreach no longer changes the internal array pointer
What PHP do I write to get to the following result?
<path>egr:0</path>
<path>office2:@FOLDER58$default</path>
If you do this:
print_r(\LaLit\XML2Array::createArray(\LaLit\Array2XML::createXML('myxml', ['ttt' => 'oo� o'])->saveXML()));
you'll get a PHP fatal error "Error parsing the XML string" even though the XML string is prepared by \LaLit\Array2XML
itself.
The reason is that a PHP string may contain characters that are invalid in XML, see https://www.w3.org/TR/xml/#NT-Char
For example, characters x00-x09 are invalid, x02 is being used in the code example above.
Getting such characters into data is easy enough, e.g., it may happen when copying content from a PDF viewer.
Seeing how there already is exception [Array2XML] Illegal character in attribute name.
possible, there should also be an exception for illegal characters in node values.
Hi !
Is the error fired because this is a numeric key ?
Shouldn't it be supported ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.