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 

Help parsing this simple XML file

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






PostPosted: Wed Mar 14, 2007 3:39 am    Post subject: Help parsing this simple XML file Reply with quote



Hi, here is the data in TEST.XML. All I want to do is find only the
entries that are "blog" entries and then put the items like "color",
"item1", "item2", and "txt", into the treeview. I can't figure out
how to do the correct check to find out whether I am on a "blog" line
or an "other" line and my loop always seems to have "null" in the
attributes :

<data>
<appointment type="start" who="me" what="it" "/>
<blog color ="blue" item1="12345"item2="abc" txt="what%20text%2E%2EI
%27m%20in%20here"/>
<blog color="red" item1="714498" item2="cde" txt="hi%20now%20%3A%28"/>
<other what="smart" how="who knows"/>
<blog color="greed" item1="1174512" item2="efg" txt="enjoy%20the
%20day"/>
<appointment type="stop" who="you" what="the others"/>
</data>

I'm trying something like this, but it doesn't work and I'm having
trouble understanding all of the levels of complexity in TXMLDoc. :

procedure TForm1.Button1Click(Sender: TObject);
const
XMLFile = 'C:\data\TEST.XML';
var
StartItemNode : IXMLNode;
ANode : IXMLNode;
sTime, sFrom, sText : widestring;
begin
try

ListView.Clear;

XMLDoc.LoadFromFile(XMLFile);
XMLDoc.Active:=True;


//
StartItemNode:=XMLDoc.DocumentElement.ChildNodes.First.ChildNodes.FindNode('blog');
StartItemNode := XMLDoc.DocumentElement.ChildNodes.First;
ANode := StartItemNode;

repeat

if (ANode is a "blog" node ) then // this is psuedocode because
I can find how to do it
begin
sColor:= ANode.ChildNodes['blog'].Attributes['color'];
sItem1 := ANode.ChildNodes['blog'].Attributes['item1'];
sTxtt := ANode.ChildNodes['blog'].Attributes['txt'];

//add to list view
with ListView.Items.Add do
begin
Caption := sColor;
SubItems.Add(sItem1);
SubItems.Add(sTxt)
end;
end;

ANode := ANode.NextSibling;
until ANode = nil;
finally
// clean up here
end;
end;

Thanks in advance!

Fred
Back to top
Guest






PostPosted: Wed Mar 14, 2007 8:06 am    Post subject: Re: Help parsing this simple XML file Reply with quote



I finally figured it out myself, though of course there are new
challenges to face, like how to parse the text. I've got that working
with StringReplace, but it goes through the entire file 10 times to
replace all the % variables. I am having trouble finding code to say
"look at each character, is it between A-Z and 0-9?, ok pass it with
no change. Does it start with a %? If so, look at the next 2
characters and match them up to replace them with what they stand for,
so %20 is a space and %2E is a period, etc.

if (Anode.NodeName = 'blog')then
begin
sColor := Anode.Attributes['color']);

instead of
// sColor := ANode.ChildNodes['blog'].Attributes['color'];

Fred
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.