1

I am build a application in Delphi that stores some configuration that is not going to be passive to query filters on the database. So I decided to create some blob text fields to store those configurations that will only be used as keys to configure some modules of the application.

In this Delphi side of the application, I am using NativeXML run-time components to decode the configuration class or record type of each module into/from XML and populate that field on the database.

My problem came when I realized that this application will have a web site module where people will register for clinical attending and this part will need to use some of the configuration stored on that XML on the database. So...

I am newbie on PHP and I wish to know from you if PHP has the ability to do that
XML<->Object\Record DeCoding or do I have to look for a library that makes it possible?

Note: If there is only a record type capacity, I will use it, but if not, I prefer to use classes


Edit:

In response to some comments on answers, I would say that I use XML instead of JSON because of this Delphi XML library that suited me well! If someone could point me to a goo JSON DeCode library to convert JSON<->Delphi Objects will really use it instead of XML because I like to work with JSON. Would that solve the problem on the PHP parsing?

NaN
  • 8,596
  • 20
  • 79
  • 153
  • I would normalize the relevant configuration into the database. While a complex configuration hierarchy may be overkill, if a simple KV configuration could be used and may be sufficient (the entire XML structure can actually me modeled as *materialized paths*, but that's getting complex again) .. I use limited XML in some databases - but I *also* use SQL Server which allows me to deal with it *inside* the database. – Paul Jul 01 '13 at 19:09
  • The later Delphi version have DBXJSON (http://docwiki.embarcadero.com/Libraries/XE4/en/Data.DBXJSON and http://docwiki.embarcadero.com/Libraries/XE2/en/Data.DBXJSON.TJSONObject, example http://stackoverflow.com/questions/10808912/how-to-parse-nested-json-object-in-delphi-xe2) and there is still SuperObject (https://code.google.com/p/superobject/, example http://stackoverflow.com/questions/14082886/superobject-extract-all). So plenty options on the Delphi side, don't know about PHP – Jan Doggen Jul 01 '13 at 20:12
  • http://pear.php.net/package/XML_Serializer - it depends a bit on the serialization format your delphi library does I don't know if there is not even already a 100% matching library. – hakre Jul 03 '13 at 20:23

2 Answers2

2

That is not that easy in PHP. However there are lots of smart folks out there, who where facing the same problem.

Paul Ferrertt has a XML-Encode Class here:

http://www.paulferrett.com/2009/encoding-an-object-in-xml-with-php/

In PHP there are multiple functions to decode a XML sheet. Start here:

http://www.php.net/manual/en/refs.xml.php http://php.net/manual/en/function.xml-parse.php

However you won' t be able to get an object back as easy as with json_decode() and that for a reason XML is not meant to transfer objects (and the like) around. You have to write your own conversion methods.

DAG
  • 6,710
  • 4
  • 39
  • 63
  • I wouldn' t say "better". Perhaps easier but this is just personal preference. – DAG Jul 01 '13 at 19:22
  • 1
    I find JSON better when .. the consumer is JavaScript. Otherwise, I'll take XML. XML is *much* more powerful than JSON and has a *wide range* of advanced tooling. In either case, I don't actually "touch" XML or JSON by hand so ease of dealing with them is merely in the libraries available. JSON works well with JavaScript because it maps 1-1 (this is important!) to JavaScript objects without needing an intermediate (and clunky) layer to access or manipulate it. – Paul Jul 01 '13 at 19:39
  • (In one of my projects I use an adapter mapping `JSON (for WS/JavaScript) <-> XML (for backend)`. Doing this once really stresses the differences in how the two different markup formats can represent equivalent data .. and results in kludges and rules required to get automatic conversions "working sensibly". The 1-1 nature of JSON is what makes it really excel in JavaScript and similar consumers; but it doesn't make it better by any means.) – Paul Jul 01 '13 at 19:48
1

I suggest you to read this : http://www.php.net/manual/en/refs.xml.php. Some of these libraries are easier to use that are others, some others are more powerful, etc.

Kevin
  • 1,000
  • 2
  • 10
  • 31