String in xmlNode delphi (or how to add xml fragment to TXMLDocument)

I have several text strings that contain well-formed XML.

I would like to be able (1) to turn these lines into IXMLNodes , then (2) add them to an existing XMLDocument . It is preferable not to declare a new XMLDocument .

Is this not possible?

Is there any easy way to accomplish something equivalent? My initial thought was to use the IXMLNode.XML (string) property and insert new lines. There is no luck like IXMLNode.XML read-only.

Here is an example if I had the following lines in a TStringList ,

 <Property Name="Version" RttiType="tkString"></Property> <Property Name="ShowSubunit" RttiType="tkBoolean"></Property> 

And I had the following XML already loaded into TXMLDocument , how can I easily add the two lines above in 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 (without a secure hack on an XML resource)?

Thanks!

+4
source share
2 answers

If you did not parse the XML fragments manually, and then manually construct the corresponding child nodes / attributes, you will have to load the fragments into the temp XMLDocument and then move their 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); 
+2
source

Check out SimpleStorage . At the moment, it is tied to OmniXML, but its powerful. What you want will look like this:

 CurrentNode.Append(StorageFromXML('<Node>Content</Node>')); 

One line of code.

0
source

Source: https://habr.com/ru/post/1482644/


All Articles