Home > Back-end >  Delphi6 read XML CDATA data
Delphi6 read XML CDATA data

Time:10-02

The following XML content
& lt; ? The XML version="1.0" encoding="GBK"?>
& lt; DataPacket Version="1.0" & gt;
& lt; The Data Name="returnMessage" & gt; & lt; ! [CDATA [& lt; & gt; & lt; & gt; & lt; & gt; connect billing software failure,]] & gt; & lt;/Data>
& lt;/DataPacket>

Can use DELPHI6 have analyze the data in a ReturnMessage? Delphi6 enter inside a loop, is to address errors, you great god help myself

Procedure TForm1. Btn1Click (Sender: TObject);
Var
XmlDuc: IxmlDocument;
Root: IXMLNode;
I: integer;
SName, sValue: string;
The begin
Try
XmlDuc:=LoadXMLDocument (' d: \ a.x ml);
XmlDuc. Active:=true;
Root:=xmlDuc. DocumentElement;
ShowMessage (IntToStr (root).childnodes) Count));
For I:=0 to root..childnodes. Do the count - 1
The begin
If not root..childnodes [I] HasAttribute (' Name ') then continue;
SName:=root.childnodes [I] the Attributes (' Name ');
SValue:=root.childnodes [I] NodeValue;
The end;
ShowMessage (sName + sValue);
Except,
The end;
The end;

CodePudding user response:

Structured MXL:
 & lt; ? The XML version="1.0"?> 
& lt; DataPacket Version="1.0" & gt;
& lt; The Data Name="returnMessage" & gt;
& lt; ! [CDATA [& lt; & gt; & lt; & gt; & lt; & gt; connect billing software failure,]] & gt;
& lt;/Data>
& lt;/DataPacket>

Structure analysis:
The root node: DataPacket, the root node is only a child node,
Child node Data, the Data is empty (no node),
& lt; The Data Name="returnMessage" & gt; Is the root node of the attribute values,
& lt; ! [CDATA [& lt; & gt; & lt; & gt; & lt; & gt; connect billing software failure,]] & gt; Is also the root node attribute values, but it's comments,
& lt; ! [CDATA [...]] & gt; Binary data; Among them "& lt;> & lt;> & lt;> Connection is billing software failure "in the annotation name attribute values,


CodePudding user response:

CDATA data can be directly take, no problem,

CodePudding user response:

The XML format is illegal,
The
& lt; ! [CDATA [& lt; & gt; & lt; & gt; & lt; & gt; connect billing software failure,]] & gt;
-
This string in Angle brackets are removed
  • Related