I Have a few text strings that contain well formed XML.
I would like to be able to (1) turn these strings into IXMLNodes
then (2) append them to an existing XMLDocument
. Preferably without declaring a new XMLDocument
first.
This doesn't seem possible?
Is there any easy way to accomplish something equivalent though? My initial thought was to use the IXMLNode.XML
(string) property and insert the new strings. No such luck as IXMLNode.XML
is Read Only.
Here is an example, if I had the following strings in a TStringList
,
<Property Name="Version" RttiType="tkString"></Property>
<Property Name="ShowSubunit" RttiType="tkBoolean"></Property>
And I had the following XML, already loaded into a TXMLDocument
, how could I easily append the two lines above into the TXMLDocument
below?
<Program Name="PFOO">
<Class Name="CFOO">
<Property Name="DBN" RttiType="tkString"/>
<Property Name="SDate" RttiType="tkClass" ClassType="TXSDATE">12/30/1899</Property>
<Property Name="XForm" RttiType="tkEnumeration">xfXML</Property>
<Property Name="Singleton" RttiType="tkBoolean">True</Property>
</Class>
</Program>
Any other (simple) ways to achieve this (no protected hack on the XML property please)?
Thank you!
Unless you parse the XML fragments manually and then construct the relevant child nodes/attributes manually, you will have to load the fragments into a temp XMLDocument and then move its nodes to the main XMLDocument as needed.
Update: For example:
Node := XmlDocument1.DocumentElement.ChildNodes[0]; // <Class> node
Node.ChildNodes.Add(LoadXMLData('<Property Name="Version" RttiType="tkString"></Property>').DocumentElement);
Node.ChildNodes.Add(LoadXMLData('<Property Name="ShowSubunit" RttiType="tkBoolean"></Property>').DocumentElement);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With