I have a C# Web Service that returns a XML as a result that will be consumed by a Delphi 7 application. Normally, I would return a .Net XmlDocument class if I had a .Net client, but, for Delphi, I'm returning a string. Below is the C# Web Service Code:
public String ReturnXML()
{
XmlDocument xmlDoc = GenerateXmlMethod();
String sXmlResult = String.Empty;
if (xmlDoc != null)
{
using (StringWriter oXml = new StringWriter())
{
xmlDoc.Save(oXml);
sXmlResult = oXml.ToString();
}
}
return sXmlResult;
}
In Delphi, I got the code below from another question here at StachOverflow, and it works perfectly if I had to load the XML and XSD from disk, but I need to load it from memory. Below is my Delphi code now:
procedure TfrmTestador.Button3Click(Sender: TObject);
var
XML, XSDL, XSDLDom: Variant;
begin
XSDLDom := CreateOLEObject('MSXML2.DOMDocument.6.0');
try
XSDLDom.async := false;
XSDLDom.load('C:\Temp\XsdFile.xsd');
XSDL := CreateOLEObject('MSXML2.XMLSchemaCache.6.0');
try
XSDL.add('',XSDLDom);
XML := CreateOLEObject('Msxml2.DOMDocument.6.0');
try
XML.validateOnParse := True;
XML.resolveExternals := True;
XML.schemas := XSDL;
XML.load('C:\Temp\XmlFile.xml');
ShowMessage(XML.parseError.reason);
finally
XML := Unassigned;
end;
finally
XSDL := Unassigned;
end;
finally
XSDLDom := Unassigned;
end;
end;
What would be the Delphi code to load the XSD and the XML from WideString variables, and have it working as the code that loads them from file, validating the XML on a fixed XSD schema that is coded into the application? Is there a better way to return the XML from C# so it is read more easily into Delphi?
Tks for your time!