I have been trying to work with Delphi 2010 and MSXML for the past few days, I am an extreme novice and need a little direction.
var
MemoryStream: TMemoryStream;
XMLPath: String;
sName: String;
XMLDoc: variant;
doc: TStringList;
begin
//unrelated code
// Create XML File to hard disk
begin
MemoryStream := TMemoryStream.Create;
IdHTTP1.get('http://somewebsite' + , MemoryStream);
MemoryStream.Position := 0;
MemoryStream.SaveToFile('data.xml');
MemoryStream.Free;
end;
// Load XML file for data display
doc:=TStringList.Create;
doc.LoadFromFile('data.xml');
XMLDoc := CreateOleObject('Msxml2.DOMDocument.6.0');
XMLDoc.async := false;
XMLDoc.LoadXML(doc.Text);
As you can see I am able to load the data into an XML file on harddisk, I then load that file into a DomDocument. I'm stuck from this point on...I want to use this data as I would a recordset in ADO (ex. SomeVariable := rs.Fields.Item('DesiredData').Value). I have done some research and read several methods. However I am unable to figure this one out. I know its got to be something trivial, I'm just not far enough along yet to understand it.
There seem to be plenty of good examples on how to write to an XML file but none on howto use the data.
If you would like to use you XML like a data container (database like) the SimpleStorage is probably what you are looking for. You can find it here:
http://www.cromis.net/blog/downloads/simplestorage/
It uses OmniXML as an XML parser. With SimpleStorage it is very easy to query and manipulate data inside XML.
I think you could do somethig with this in the next lines:
The parameter for selectSingleNode is basicaly an XPath expression, so you can query attribute nodes like:
//route/to/node/@attrib
Here is the MSDN reference to selectSingleNode: http://msdn.microsoft.com/en-us/library/ms757846(v=VS.85).aspx and here is the XPath sintax: http://msdn.microsoft.com/en-us/library/ms256471(v=VS.85).aspx
Also, I can point you to a good XML library for XML Manipulation from Delphi that is also compatible with MSXML but you don't have to use variants directly : http://www.omnixml.com/
And a much better approach if your XML doesn't change much, is to use the XML Data Binding wizard, that basically creates a complete object model from a XML or XSD (it makes to create or read an XML as easy as instanciate a composite object, creating the classes and methods you need): http://www.youtube.com/watch?v=4D78MG4CaAI&feature=player_embedded