Related articles |
---|
Sugestions wanted for XML parser kaizer@mail.pt (kz) (2002-05-12) |
Re: Sugestions wanted for XML parser joachim_d@gmx.de (Joachim Durchholz) (2002-05-13) |
Re: Sugestions wanted for XML parser jimbo@radiks.net (2002-05-13) |
From: | kz <kaizer@mail.pt> |
Newsgroups: | comp.compilers |
Date: | 12 May 2002 00:11:36 -0400 |
Organization: | Compilers Central |
Keywords: | parse, question, XML |
Posted-Date: | 12 May 2002 00:11:36 EDT |
Hello.
I'm a beginner in all this parsing subject, and I'm interested in
writing a simple XML parser.
As I'm really a beginner, I'm only planning that the parser analyzes a
XML input file, and returns an array with tag description (tag name,
tag value and parent tag id), so it won't be validating with a DTD
file. Also, it wont be checking for version tags or anything like
that.
I'm planning to write it has follows:
loop ( read file char by char )
if previous_char = "<" and char = "?"
// version tag; ignore
else if previous_char = "<"
// place = tag name
else if previous_char = ">" and char <> "<"
// place = tag value
(..) (and so on, checking for tag combinations with conditions)
(and then copy values to the tags array, according to the place)
previous_char = char
(...)
This would transform something like:
<clients>
<client>
<id>1</id>
</client>
<client>
<id>2</id>
</client>
</clients>
into an array that looks something like this:
structure[tag_name] = clients
structure[tag_id] = 1
structure[tag_value] = (none)
structure[tag_parent] = (none)
structure[tag_name] = client
structure[tag_id] = 2
structure[tag_value] = (none)
structure[tag_parent] = 1
structure[tag_name] = id
structure[tag_id] = 3
structure[tag_value] = 1
structure[tag_parent] = 2
structure[tag_name] = client
structure[tag_id] = 4
structure[tag_value] = (none)
structure[tag_parent] = 1
structure[tag_name] = id
structure[tag_id] = 5
structure[tag_value] = 2
structure[tag_parent] = 4
So, basicly... is this a good way to "go for it" ?
Should I use another method ?
Thanks.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.