Convert xml to MAP in php using simplexml, NOT json - php

I'm trying to figure out how to take a simple custom xml file (its actually an EML file, but simpeXML works with it anyway) and take tagnames and the text that follows (i think simpleXML calls them children) and put them into a MAP, with key/value pairs. I've looked at some examples on this site and others about converting to arrays and such but they all seem extremely complicated for my needs. I should note that my custom xml does not contain ANY attributes and this conversion only needs to work with MY custom xml file and not any others ever.
So a simple example of my eml file is here
<lesson>
<unit>4</unit>
</lesson>
So then basically what I would want is a MAP, or whatever a key/value collection is called in php that would give me:
Map[0](lesson,null)
Map[1](unit,4)
It's important that I get the null values (or an empty string is ok too), so I can verify that the eml file is valid. I need to validate it with php, not using a namespace validator or a dtd file or however that is done. So the first key/value pair, or the root tag, HAS to be lesson, and then ill also verify that there is a unit tag, then a title tag, then at least one other type of tag etc...I can do that easy if i can get everything into a key/value collection. Also, there are many tagnames that are the same, so keys should be not-unique. However for the value, they should be unique, but only to the tag name. So unit can only one one "4", but another tag, lets say imageID could also have "4". This is not a requirement but a "nice to have" and I can probably figure that out if its not simple. But if its REALLY hard then I will skip it all together.
I hope this makes sense.
And no, I don't think Im allowed to use json. I'm sure it can be done in simpleXMl but if its impossible, then please provide a method to do it in json (assuming that json is included with PHP and not an extension that has to be loaded).
This is university homework, so I can't use extensions or anything else that would require anything beyond what comes with the XAMPP basic package (php, mysql, apache etc...).

Really surprised I got no votes or views or answers or anything on this. I did figure this out in the end. Oh yeah...got the tumbleweed badge for this too!
Anyway the answer was actually quite simple. I used the simplexml_load_file function in PHP which actually supports any kind of xml-style. So after running this,
$eml = simplexml_load_file("unit.eml");
I then did things like this
foreach ($eml->children() as $child)
$tag = $child->getName();
$tagInfo = $child;
And used $tag and $tagInfo to iterate through my eml and get everything I needed.

Related

How can I code a PHP file upload specificly for json files that is secure and wont allow Php or html to be uploaded

I am working on a site that allows models to be uploaded.
the models are json format like this :
{"meta":{"format_version":"3.0","model_format":"bedrock_old","box_uv":true},"name":"crocodile","geo_name":"crocodile","resolution":{"width":128,"height":128},"elements":[{"name":"body","from":[-4.5,3,-11],"to":[4.5,12,9],"autouv":0,"color":0,"origin":[0,0,0],"uuid":"dc9860c3-1826-d5a0-5475-140558d9bcbd"},{"name":"head","from":[-4,3.5,-13],"to":[4,11.5,-11],"autouv":0,"color":1,"origin":[0,0,0],"uv_offset":[44,45],"uuid":"64585c76-5a21-4d25-e334-afdc62e32bec"},{"name":"jawtop","from":[-4,7,-19],"to":[4,11,-13],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[60,29],"uuid":"08ff348f-2450-1885-c0f6-1754cd0361e0"},{"name":"jawtop","from":[-3,7,-25],"to":[3,10,-19],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[0,45],"uuid":"ce05463f-09fe-45c3-f038-016152a1d962"},{"name":"jawtop","from":[-2,7,-29],"to":[2,9,-25],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[22,55],"uuid":"68004a0b-3d5e-1628-bc01-f97fc31d7add"},{"name":"jawtop","from":[-3,11,-17],"to":[-1,12,-14],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[0,71],"uuid":"1f51dc8c-bce3-f6b1-e3ce-b8bd95cfb0b6"},{"name":"jawtop","from":[1,11,-17],"to":[3,12,-14],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[10,71],"uuid":"a5e2642b-891a-8531-068a-f58f6773086d"},{"name":"jawbottom","from":[-3.5,4,-24],"to":[3.5,7,-13],"autouv":0,"color":3,"origin":[0,0,0],"uv_offset":[58,0],"uuid":"ad1c59ee-6f3f-07ef-fcdc-190444c48dc7"},{"name":"jawbottom","from":[-2.5,5,-30],"to":[2.5,7,-24],"autouv":0,"color":3,"origin":[0,0,0],"uv_offset":[0,55],"uuid":"750a2256-945c-2ea9-b2a3-eaf1af4b55ec"},{"name":"leg0","from":[3.5,2,5],"to":[5.5,7,8],"autouv":0,"color":4,"origin":[0,0,0],"uv_offset":[20,63],"uuid":"80425fb4-9022-e3f0-369c-4327b745fb92"},{"name":"leg0bot","from":[3.5,-1,6],"to":[5.5,3,8],"autouv":0,"color":5,"origin":[0,0,0],"uv_offset":[28,71],"uuid":"6afca6bb-c3b1-3284-1c00-ef2028a079aa"},{"name":"leg1","from":[-5.5,2,5],"to":[-3.5,7,8],"autouv":0,"color":6,"origin":[0,0,0],"uv_offset":[52,55],"uuid":"a7c6896b-f5af-9216-3cd7-0ad96fe57966"},{"name":"leg1bot","from":[-5.5,-1,6],"to":[-3.5,3,8],"autouv":0,"color":7,"origin":[0,0,0],"uv_offset":[20,71],"uuid":"675b7a00-486a-568b-9c51-09cef03b2abd"},{"name":"leg2","from":[3.5,2,-9],"to":[5.5,7,-6],"autouv":0,"color":0,"origin":[0,0,0],"uv_offset":[0,63],"uuid":"59aeddb8-d40b-8894-466c-ce509b62ef2f"},{"name":"leg2bot","from":[3.5,-2,-8],"to":[5.5,2,-6],"autouv":0,"color":1,"origin":[0,0,0],"uv_offset":[48,63],"uuid":"240ac047-9697-f70d-88af-2c948ef0a1a2"},{"name":"leg3","from":[-5.5,2,-9],"to":[-3.5,7,-6],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[10,63],"uuid":"269587ec-ed0a-74b0-0aac-d1e3f4b757db"},{"name":"leg3bot","from":[-5.5,-2,-8],"to":[-3.5,2,-6],"autouv":0,"color":3,"origin":[0,0,0],"uv_offset":[40,63],"uuid":"97f9b166-f557-ac6b-853e-74e476343c85"},{"name":"tail0","from":[-3.5,4,9],"to":[3.5,11,18],"autouv":0,"color":4,"origin":[0,0,0],"uv_offset":[0,29],"uuid":"eee0a07c-244b-e299-cdbb-f4722dd1d4b8"},{"name":"tail1","from":[-2.5,5,18],"to":[2.5,10,27],"autouv":0,"color":5,"origin":[0,0,0],"uv_offset":[32,29],"uuid":"0688b6e6-6366-6584-3e85-b6308f361a30"},{"name":"tail2","from":[-1.5,6,27],"to":[1.5,9,34],"autouv":0,"color":6,"origin":[0,0,0],"uv_offset":[24,45],"uuid":"37baa016-fdda-f2d8-6b0f-cbec8889a45d"},{"name":"tail3","from":[-0.5,6.5,34],"to":[0.5,8.5,40],"autouv":0,"color":7,"origin":[0,0,0],"uv_offset":[38,55],"uuid":"89277697-7dfb-6b42-2ea4-3d66a07425bb"},{"name":"tail4","from":[-0.5,7,40],"to":[0.5,8,44],"autouv":0,"color":0,"origin":[0,0,0],"uv_offset":[30,63],"uuid":"dc801a46-d1f8-2afd-1221-cbf021fda901"}],"outliner":[{"name":"body","uuid":"08b60937-c59c-d629-428d-dbc1b47bf899","export":true,"isOpen":true,"visibility":true,"autouv":0,"origin":[0,9,0],"children":["dc9860c3-1826-d5a0-5475-140558d9bcbd",{"name":"head","uuid":"794cb49d-09ea-b58a-d62f-7909c5329824","export":true,"isOpen":true,"visibility":true,"autouv":0,"origin":[0,9.5,-11],"children":["64585c76-5a21-4d25-e334-afdc62e32bec",{"name":"jawtop","uuid":"864311e9-ad20-750e-c1bc-d9003d8e09fa","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9,-13],"children":["08ff348f-2450-1885-c0f6-1754cd0361e0","ce05463f-09fe-45c3-f038-016152a1d962","68004a0b-3d5e-1628-bc01-f97fc31d7add","1f51dc8c-bce3-f6b1-e3ce-b8bd95cfb0b6","a5e2642b-891a-8531-068a-f58f6773086d"]},{"name":"jawbottom","uuid":"ca3610f0-82e8-c919-0b09-cc448af7db2b","export":true,"isOpen":true,"visibility":true,"autouv":0,"origin":[0,9,-13],"children":["ad1c59ee-6f3f-07ef-fcdc-190444c48dc7","750a2256-945c-2ea9-b2a3-eaf1af4b55ec"]}]},{"name":"leg0","shade":false,"uuid":"1c25265d-b108-2e3a-b48c-1840a8679882","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[3.5,9,6.5],"rotation":[-15,0,-30],"children":["80425fb4-9022-e3f0-369c-4327b745fb92",{"name":"leg0bot","shade":false,"uuid":"ccf50fe0-f61d-a385-ae91-1b9cf1cd704a","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[4.5,4,6],"rotation":[50,0,0],"children":["6afca6bb-c3b1-3284-1c00-ef2028a079aa"]}]},{"name":"leg1","uuid":"742bd91e-8c68-346f-8171-5fd796e5168b","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-3.5,9,6.5],"rotation":[-15,0,30],"children":["a7c6896b-f5af-9216-3cd7-0ad96fe57966",{"name":"leg1bot","uuid":"f9aac351-dd57-f3c7-8888-aecf46f41bf0","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-4.5,4,6],"rotation":[50,0,0],"children":["675b7a00-486a-568b-9c51-09cef03b2abd"]}]},{"name":"leg2","shade":false,"uuid":"756ef132-6c43-8a05-f00e-89efded63842","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[3.5,9,-7.5],"rotation":[-15,0,-30],"children":["59aeddb8-d40b-8894-466c-ce509b62ef2f",{"name":"leg2bot","shade":false,"uuid":"dccb0f87-61fd-f919-3e77-ea01d2b7b921","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[4.5,4,-7],"rotation":[50,0,0],"children":["240ac047-9697-f70d-88af-2c948ef0a1a2"]}]},{"name":"leg3","uuid":"8b2f9b00-b22c-5b3c-a530-436a5d9d4a7a","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-3.5,9,-7.5],"rotation":[-15,0,30],"children":["269587ec-ed0a-74b0-0aac-d1e3f4b757db",{"name":"leg3bot","uuid":"a91c7b0e-3d6f-4a0e-18bf-c83531e1ef2e","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-4.5,4,-7],"rotation":[50,0,0],"children":["97f9b166-f557-ac6b-853e-74e476343c85"]}]},{"name":"tail0","uuid":"c3e0f719-cb90-e79f-8664-3b6bc1531c0d","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,9],"children":["eee0a07c-244b-e299-cdbb-f4722dd1d4b8",{"name":"tail1","uuid":"0f292741-56cb-0d10-fc48-bb6e00ca2755","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,18],"children":["0688b6e6-6366-6584-3e85-b6308f361a30",{"name":"tail2","uuid":"38c0f23e-4aae-37ba-340d-95a042b86cbf","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,27],"children":["37baa016-fdda-f2d8-6b0f-cbec8889a45d",{"name":"tail3","uuid":"ba8b9331-6926-6d51-3f9c-b206a4f971b7","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,34],"children":["89277697-7dfb-6b42-2ea4-3d66a07425bb",{"name":"tail4","uuid":"e70eca10-4cd6-05eb-d828-02e363c9a3a5","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,40],"children":["dc801a46-d1f8-2afd-1221-cbf021fda901"]}]}]}]}]}]}],"textures":[{"path":"crocodile.png","name":"crocodile.png","folder":"","namespace":"","id":"0","particle":false,"mode":"bitmap","saved":true,"uuid":"c62c819f-3c1a-aefb-00ff-415b02e2f7ac","source":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAcyElEQVR4Xu2dCZRddX3Hf/fts89kxQhZCEvUo6BQDQlJCG5d1IoeJCRshpAEEqEICNJqrYpiW3tsKWpRsFVL4egBUYvVgiACcupCrdoAAZIANhCyzJLZ3nJvz+f3v7+XIcyb8zLzcucm3Ms5zMvMe/f/f//f97cv15MGX8fO6wgqvifpVCDDRU8KuUCGip40FwIpljxJpQJZfdYiSac9SadTUqn44vuBFPJZ8VKeVMq+lEoVueb6u70Gb63u2/3jp88IHr3l19JTKlU/05HNyhtXnyDlMvv19ffpTErKJV9K5Yq0NOfkQx/7zqTtue4vt98bG77h447uCLgpRE+nRAIWDDzJ53wFBGd3yfmLJZ/LyOBQUZqbcrK3f1iy2bR4nifZTFqGhktyzWcnDwAv/vfVwTXv+9bLAHD9HWfK1771WwUBBC+WKlLIZ6R/oKggvvZzP2j4eY6XsPV+ruEbnv3qziDliWSzTgLkso7zkQDlikgmLbJ21VIZLpaV61MpTw+yqZCVvr1DThoUsnLFJ7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ejdkApJvIOJ0fOAP91wANhkcXtYNHEAXuv8HiJ64QOn7PcuCOUeE8Pk0aRw84BpOKEPNBwAE9pN8uHITyABQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7+b/AZovzmIGTS/bAAAAAElFTkSuQmCC"}]}
The file is called crocodile.bbmodel
I am looking for a way to allow users to upload .bbmodel files that is safe so that no web shells or malicious code can sneak its way past the upload can you guys help?
From what I know there is no magic button that will let you do this. that said the first thing you will want to do is make sure the uploaded file is valid json. check this Fastest way to check if a string is JSON in PHP?
Next you will need to define which fields in json are valid and what types the value should contain. for this I would create a skeleton versioin of the json string and store it a database field. Examining your json further you might need multiple skeletons for the various repeat or nested elements. eg one for meta like this
"meta":{"format_version":"","model_format":"","box_uv":}
you would want another skeleton for elements probably describing the keys for a single 'element'. and of course validate the textures.source nodes against a base64 encoding.
Next you will want to decide what are acceptable types for each of the field values. compare each field of the submitted json against an acceptable type you define.
once you do all of this validation you can be reasonably sure you have a valid file...I won't say secure or non-malicious but, done properly it will help you ingest the file without errors.
Still not guaranteed to be 'secure' but, it is a reasonable approach and would probably satisfy most due diligence critiques. If anyone can improve and provide more steps or different tricks to secure something like this I'd be glad to hear it.

Parse XML data to JSON

In our environment we use MS SQL w/ stored procedures. In those procedures we return our results as XML and when access the data as we need to.
I'm introducing some charts into our tools which are 3rd party and require specific formats in order to operate and I am running into an issue.
In this screenshot, you are able to see what the structure should look like which I can get to work with the plugin just fine. The issue is with how SimpleXML handles single result sets.
As you can see in the image below, with one result item, it is no longer formatted as an array. The problem being is that the plugin expects to find the data in the format in the first example, but when there is only one value, it doesn't store it as an array.
As you can see from this image, the dataset for the escalationTypes is in the array format where the one below, submittedByDepartment is not.
I am trying to find out if there is something I can do to fix the root of this problem, with SimpleXML. Is this a common issue found with SimpleXML with a workaround?
UPDATE
Here is a sample of the XML Object I am working with: http://pastebin.com/uPh0m3qX
I'm not 100% clear what your required structure is, but in general, it's not a good idea to jump straight from XML to JSON or vice versa. Both can represent data in various ways, and what you really want is to extract data from one and turn it into the other.
Note that this is what SimpleXML is designed to help you with - it never contains any arrays, but it gives you an API which helps you extract the data you need.
If I understand correctly, you want to build an array from each of the dataset elements, and put those into your JSON, so you'd want something like this:
foreach ( $xml->children() as $item_name => $item ) {
foreach ( $item->dataset as $dataset ) {
$json[$item_name]['dataset'] = (array)$dataset->attributes();
}
}
Note that neither of those loops will behave differently if there is only one item to loop over. SimpleXML decides whether to behave like an array or an object based on how you use it, not based on what the XML looks like.
Note that while you can build a more general XML to array (or XML to JSON) function, getting it to always give the desired output from any input will probably take more time, and lead to harder-to-debug code, than writing specific code like the above.
you can declare the object as an array by adding (array) before referencing the variable. (array)$wasobject

What is the best way to find a specified element using PHP's SimpleXMLElement class?

The project that I'm currently working on involves translating a website that was written in Python to PHP code. The part I'm doing now requires me to send $_GET requests to a web server. The response that I get back is always in XML format, so I'm using the *simplexml_load_file()* function to fetch the result.
I need to parse through the XML that the web server sends back to me. Python had a nice library called BeautifulStoneSoup, which had a find() method that returned the contents of a specified attribute.
After looking at the list of PHP functions at http://php.net/manual/en/book.simplexml.php, I cannot seem to find anything that allows me to specify an attribute name and get the contents. Keep in mind that attribute I may be looking for is not necessarily going to always be one level deep into the XML array. It may be several dimensions into the array.
I can provide an example if this wasn't specific enough. Thanks for the help, friends!
Xpath sounds like what your looking for. It allows for searches to be made within any level of an XML directory.
The following example looks multiple levels deep with an xml directory and checks if the description node contains whatever is held within $txtSearch
$holidayDoc = simplexml_load_file($url);
$qry = "//channel/item[description[contains(text(),\"$txtSearch\")]]";
$holidayDoc->xpath($qry);
Results can then be iterated through using a foreach loop
You can run an XPath query:
$xml->xpath('//#myattribute')

how works php soap server with attributes or is there a library that understands attributes?

I was trying to make a soap server in PHP and that works good, only the wsdl requires a attribute OptIn like:
<EmailAdresses>
<Email OptIn="true">email#domain.com</Email>
</EmailAdresses>
Is there a good php library/classes that works with attributes?
so that the Web service can return an array or something like that in a certain way and that those revenues to xml with attributes.
or how it works with the standard soap server from php ?
because good documentation is hard to find.
thanks in advance
I've worked with SOAP services written in a number of languages, and I've never yet seen one which uses XML attributes -- they always simply use XML elements with a value inside the element (either a string or further elements).
I'm not saying you can't use attributes, but it seems that simple name-value pairs are a better fit for the kinds of data structures that most programming languages want to work with (ie simple variables or array trees).
But your question piqued my curiosity, so I've done a bit of digging for you.
As you say, the PHP manual really doesn't seem to be particularly forthcoming on the subject (which is unusual - it's generally quite a good resource), but if you really want to create attributes in your SOAP XML, I did find a few snippets which might help.
One suggestion which came up a few times was to use underscore as an array element in your data structure, and this would then become the value for the element, and other array keys would would become the attributes. Something like this:
$mydata = array('EmailAdresses' => array(
'Email' => array(
'_' => 'email#domain.com',
'OptIn' => 'true')
)
);
The other suggestion I found was to create it as an object rather than as an array, using PHP's SimpleXML library, since this obviously explicitly allows the creation of XML attributes.
Sorry I don't have time to test those suggestions right now, but I hope that helps.

read an xml file into database

I want to store the contents of an xml file in the database. Is there an easy way to do it?
Can i write some script that can do the task for me?
The schema of the XML file looks like this:
<schedule start="20100727120000 +0530" stop="20100727160000 +0530" ch_id="0210.CHNAME.in">
<title>Title_info</title>
<date>20100727</date>
<category>cat_02</category>
</schedule>
One thing to note is:
How do I read the start time? I need the time +0530 added to the time?
Thank you so much.
You'll probably want to create a table called schedules that matches your data, then read the contents of the XML file with an XML parser of your choice. SimpleXML might be the right tool for this job.
As for the dates, I recommend you try using the function date_parse_from_format().
look up simple_xml on the php page - off hand I'm not too hot on it, but basically you will end up with a loop which will add your data to an object eg:
$xml
and you will be able to call tags as such $xml->schedule->title $xml->schedule->date and $xml->schedule->category and you will be able to call attributes as such $xml->schedule[start] but you might wanna check that.
I had to do this recently for a client, and this was the best way I could find. The attributes may be tricky - I can't quite remember but you might have to look into namespaces and such... anyway, find simple_xml and you're on the right tracks.

Categories