BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Decoding XML in delphi 6

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML
View previous topic :: View next topic  
Author Message
SD99
Guest





PostPosted: Thu Feb 08, 2007 9:42 pm    Post subject: Decoding XML in delphi 6 Reply with quote



Hi

I'm writing an app that will send an XML file to a server and the receive a
response, the response will vary depending upon the validity of the file I
send to the server. I will either receive a file with the data, or one
indicating an error was found.

Problem is I can't figure out where to start with the decoding of the
received file, I need to be able to firstly determine if the returned file
is an error file or valid one. Then I need to strip out all the information
that the file has.

Anyone got any ideas? Samples of the xml are attached at bottom of this
message.
If needed I can always post the design document for the transmit and receive
files on here.

Thanks


Sample of Error XML file:

<?xml version=’1.0’ ?>
<xOasis>
<CLSResponse type=’Error’ version=’3.0’> <!—
Required 
<Result> <!—
Required 
<Text><![CDATA[<text>]]></Text> <!—
Required 
<Code><![CDATA[<code>]]></Code> <!—
Required 
</Result>
</CLSResponse>
</xOasis>




Sample of valid XML File:

<?xml version=’1.0’?>
<xOasis>
<CLSResponse type="Esc-Query" version="3.0">
<CLI><![CDATA[01932755555]]></CLI>
<NumberOfLocations><![CDATA[1]]></NumberOfLocations>
<Locations>
<Location>
<CallID>
<High><![CDATA[1080826235]]></High>
<Low><![CDATA[1335583]]></Low>
</CallID>
<CallerIdentification>
<NetworkCLI><![CDATA[01932755555]]></NetworkCLI>
<PresentationCLI><![CDATA[+4401932755555]]></PresentationCLI>
<CallBackNumber><![CDATA[32198765]]></CallBackNumber>
<MobileOrLandLine><![CDATA[Landline]></ MobileOrLandLine>
</CallerIdentification>
<LocationSource>
<RequestDateTime><![CDATA[20050420111733]]></RequestDateTime>
<SourceType><![CDATA[SND]]></SourceType>
<SourceIdentity><![CDATA[FRNT]]></SourceIdentity>
<SearchCriteria><![CDATA[01932755555]]></SearchCriteria>
<SourceStatus><![CDATA[SND000;system available]]></SourceStatus>
<CallerInformation>
<Name><![CDATA[TEST NUMBER 1]]></Name>
<Address1><![CDATA[VOLT DELTA EUROPE LTD]]></Address1>
<Address2><![CDATA[DOLPHIN HOUSE]]></Address2>
<Address3><![CDATA[WINDMILL ROAD]]></Address3>
<Address4><![CDATA[SUNBURY ON THAMES]]></Address4>
<Address5><![CDATA[MIDDLESEX]]></Address5>
<Address6><![CDATA[]]></Address6>
<PostCode><![CDATA[TW16 7HT]]></PostCode>
</CallerInformation>
</LocationSource>
<Service>
<Provider><![CDATA[ACME]]></Provider>
<Type><![CDATA[9,OASIS-EMG,Emergency Service Calls]]></Type>
<System><![CDATA[0,VDE,Volt Delta Europe]]></System>
<Platform><![CDATA[0,SS1,OASIS Switch Site 1]]></Platform>
<Centre><![CDATA[1,NE2,North East Bureau 2]]></Centre>
</Service>
</Location>
</Locations>
<Result>
<Text><![CDATA[Okay]]></Text>
<Code><![CDATA[CLS000]]></Code>
<AdditionalInfo><![CDATA[]]></AdditionalInfo>
</Result>
</CLSResponse>
</xOasis>
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Feb 09, 2007 12:46 am    Post subject: Re: Decoding XML in delphi 6 Reply with quote



"SD99" <nospam (AT) nospam (DOT) com> wrote in message
news:45cb44c6$1 (AT) newsgroups (DOT) borland.com...

Quote:
Problem is I can't figure out where to start with the decoding
of the received file, I need to be able to firstly determine if the
returned file is an error file or valid one. Then I need to strip
out all the information that the file has.

Anyone got any ideas?

Have you looked at Borland's TXMLDocument component (or IXMLDocument
interface) yet?

Quote:
Samples of the xml are attached at bottom of this message.

uses
XMLDoc;

var
Doc: IXMLDocument;
ResponseNode: IXMLNode;
type: String;
begin
Doc := LoadXMLData('Your XML Here');
ResponseNode :=
Doc.DocumentElement.ChildNodes.FindNode('CLSResponse');
if ResponseNode <> nil then
begin
type := ResponseNode.Attributes['type'];
if type = 'Error' then
begin
// process error information as needed ...
end
else if type = 'Esc-Query' then
begin
// process success information as needed ...
end else
begin
// unknown type, do something ...
end;
end else
begin
// unknown response, do something ...
end;
end;


Gambit
Back to top
SD99
Guest





PostPosted: Fri Feb 09, 2007 9:13 am    Post subject: Re: Decoding XML in delphi 6 Reply with quote



Yes I am using the TXMLDocument component, was just needing a nudge in
correct direction, lol.
I'm new to using XML in Delphi, so wasn't quite sure how to go about it.

Thanks



"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45cb702e$1 (AT) newsgroups (DOT) borland.com...
Quote:

"SD99" <nospam (AT) nospam (DOT) com> wrote in message
news:45cb44c6$1 (AT) newsgroups (DOT) borland.com...

Problem is I can't figure out where to start with the decoding
of the received file, I need to be able to firstly determine if the
returned file is an error file or valid one. Then I need to strip
out all the information that the file has.

Anyone got any ideas?

Have you looked at Borland's TXMLDocument component (or IXMLDocument
interface) yet?

Samples of the xml are attached at bottom of this message.

uses
XMLDoc;

var
Doc: IXMLDocument;
ResponseNode: IXMLNode;
type: String;
begin
Doc := LoadXMLData('Your XML Here');
ResponseNode :=
Doc.DocumentElement.ChildNodes.FindNode('CLSResponse');
if ResponseNode <> nil then
begin
type := ResponseNode.Attributes['type'];
if type = 'Error' then
begin
// process error information as needed ...
end
else if type = 'Esc-Query' then
begin
// process success information as needed ...
end else
begin
// unknown type, do something ...
end;
end else
begin
// unknown response, do something ...
end;
end;


Gambit

Back to top
SD99
Guest





PostPosted: Fri Feb 09, 2007 7:18 pm    Post subject: Re: Decoding XML in delphi 6 Reply with quote

One more thing

Have you seen any code that can be used to extract the Nodes names and the
CData for these node to either a tlist or something similar?

Thanks




"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
news:45cb702e$1 (AT) newsgroups (DOT) borland.com...
Quote:

"SD99" <nospam (AT) nospam (DOT) com> wrote in message
news:45cb44c6$1 (AT) newsgroups (DOT) borland.com...

Problem is I can't figure out where to start with the decoding
of the received file, I need to be able to firstly determine if the
returned file is an error file or valid one. Then I need to strip
out all the information that the file has.

Anyone got any ideas?

Have you looked at Borland's TXMLDocument component (or IXMLDocument
interface) yet?

Samples of the xml are attached at bottom of this message.

uses
XMLDoc;

var
Doc: IXMLDocument;
ResponseNode: IXMLNode;
type: String;
begin
Doc := LoadXMLData('Your XML Here');
ResponseNode :=
Doc.DocumentElement.ChildNodes.FindNode('CLSResponse');
if ResponseNode <> nil then
begin
type := ResponseNode.Attributes['type'];
if type = 'Error' then
begin
// process error information as needed ...
end
else if type = 'Esc-Query' then
begin
// process success information as needed ...
end else
begin
// unknown type, do something ...
end;
end else
begin
// unknown response, do something ...
end;
end;


Gambit

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Feb 10, 2007 2:30 am    Post subject: Re: Decoding XML in delphi 6 Reply with quote

"SD99" <nospam (AT) nospam (DOT) com> wrote in message
news:45cc7492 (AT) newsgroups (DOT) borland.com...

Quote:
Have you seen any code that can be used to extract the
Nodes names and the CData for these node to either a
tlist or something similar?

Please read the VCL documentation. The properties and methods of
IXMLNode are documented.


Gambit
Back to top
Pascal
Guest





PostPosted: Tue Feb 13, 2007 3:15 am    Post subject: Re: Decoding XML in delphi 6 Reply with quote

I sometimes need to dynamically figure out what is in an xml file.
Here is a naive search I wrote (in D7):

const
XML_PATH_DELIMITER = '\';

function FindChildNode(AParentNode: IXMLNode; const ANodeName:
string): IXMLNode;
var
I: Integer;
begin
for I := 0 to AParentNode.ChildNodes.Count - 1 do
begin
Result := AParentNode.ChildNodes[I];
if Result.NodeName = ANodeName then
Exit;
end;
Result := nil;
end;

function MatchFirst(const APath: string; ANode: IXMLNode): IXMLNode;
var
I: Integer;
begin
Result := ANode;
with TStringList.Create do
try
Delimiter := XML_PATH_DELIMITER;
DelimitedText := APath;
for I := 0 to Count - 1 do
begin
Result := FindChildNode(Result, Strings[I]);
if Result = nil then
Exit;
end;
finally
Free;
end;
end;

function MatchNext(ANode: IXMLNode): IXMLNode;
begin
Result := ANode.NextSibling;
while (Result <> nil) and
(Result.NodeName <> ANode.NodeName) do
Result := Result.NextSibling;
end;

// Usage example:
// XMLDocument1 has an xml of one type
// XMLDocument2 has the other
// Note that you could make a function that extracts the attribute

procedure TForm1.Button1Click(Sender: TObject);
var
CLSResponseNode: IXMLNode;
CLSResponseType: string;
begin
CLSResponseNode := MatchFirst('xOasis\CLSResponse',
XMLDocument1.Node);
if CLSResponseNode <> nil then
begin
if CLSResponseNode.HasAttribute('type') then
begin
CLSResponseType := CLSResponseNode.Attributes['type'];
Memo1.Lines.Add(CLSResponseType); // 'Error' type
end;
end;

CLSResponseNode := MatchFirst('xOasis\CLSResponse',
XMLDocument2.Node);
if CLSResponseNode <> nil then
begin
if CLSResponseNode.HasAttribute('type') then
begin
CLSResponseType := CLSResponseNode.Attributes['type'];
Memo1.Lines.Add(CLSResponseType); // 'Esc-Query' type
end;
end;
end;

HTH,

--Pascal
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi XML All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.