Parsing part of XML document type

Posted on 2003-04-01
Medium Priority
Last Modified: 2013-12-03
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.

Question by:kapot
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

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


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

look for IXMLNode properties such as

AttributeNodes (makes the attributes handle like normal nodes through XMLDocument1.ChildNodes)

a good document on xml parsing is


Expert Comment

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.



Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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
Course of the Month13 days, 4 hours left to enroll

777 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