Search code examples
jsonxml-serializationdelphi-prismoxygene

Parsing XML or JSON in Delphi Prism


I am trying to parse either XML or JSON (doesn't matter, the API I'm interested in provides both) in Delphi Prism but all Tutorials and Howtos show the Delphi code which is no longer available in Prism.

Could you please help me?

(I'm not trying to compile Prism code from XML, I'm trying to parse XML in Prism ^^)


Solution

  • Pretty easy really. Make sure you have a framework version 3.5 and above version of a new project. Then you have two choices, if you have an XSD you can create classes from xml. You can do this with the XSD.EXE tool (/language:Oxygene). If you want to parse any xml, you can use the XDocument class defined in the System.Xml.Linq namespace:

    var lDoc := new XDocument();
    lDoc.Load(streamorfile);
    var lAllTextValuesInNodeNameNodes := from x in lDoc.Elements where x.Name = 'nodename' select x.Value;