Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Parsing part of XML document type

Posted on 2003-04-01
2
Medium Priority
?
225 Views
Last Modified: 2013-12-03
Hi,
As far as I know, HTML file is a XML document, right?

I need to know how to parse part of HTML file, for example I have a string like this :

   s := '<TR><TH>Header1</TH><TH>Header2</TH><TH>Header3</TH></TR>';

I want to retrieve from s for each component .. <TR> ... <TH> ... Header1 ...

My goal is to reproduce s to be like this (for example) :

   s := '<TR bgcolor="#CCFFFF"><TH><Font size="1">Header1</Font></TH>...';

Anyone can give me an example how to achieve this?

I tried to use TXMLDocument component for this, but I really dont understand how to do it.

Thanks for any help.

Regards,
kapot
0
Comment
Question by:kapot
2 Comments
 
LVL 1

Accepted Solution

by:
grolschisgood earned 80 total points
ID: 8245198
TXMLDocument is the best method as it provides you all the functions to perform what you require.  using TXMLDocument you need to perform the following steps

1. load the string

XMLDocument1.LoadFromXML(s); //where 's' is your string in above example

2.  iterate through the nodes of the XMLDocument and either set the values of the nodes or change the attributes of the nodes.  This is quite a process and involves a lot of iteration

study up on the following properties of XMLDocument1

DocumentElement
ChildNodes

do a search for IXMLNode (this represents a single node in a XML doc or string)

look for IXMLNode properties such as

NodeName
NodeType
NodeValue
hasChildNodes
ChildNodes
Attributes
AttributeNodes (makes the attributes handle like normal nodes through XMLDocument1.ChildNodes)

a good document on xml parsing is

http://homepages.borland.com/ccalvert/TechPapers/Delphi/XMLSimple/XMLSimple.html
0
 

Expert Comment

by:olagutt
ID: 8245204
Hi kapot,

-Load the HTML file into a TXMLDocument instance.
-Usage of the component may be tricky, but if you look at it as a set of nodes and run through them and copy the information you want, write the modified tags and attributes into an new instance, then write this into a string or file.

If you need information to do this, have a look on the VCL reference.

Parsing of the string using string-operators will do the trick as well, but might be a bit difficult.

Regards,
Ola


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question