Bjoern Hoehrmann
Usenet Archive
- Joined
- Aug 15, 2000
- Messages
- 719
- Reaction score
- 0
* Roman Mashak wrote in comp.text.xml:
Your second <NODE1> should probably be <NODE2> (otherwise the start- and end-tags do not match up), but other than that it certainly is XML. You are free to choose (when designing a new XML format) whether you use an attribute or element to encode some information.
Expart reports the text through the `characters` callback. You have to setup a handler for it and accumulate the text reported to it; then process the text e.g. in the end_element handler. There is no direct way get to the text when using Expat.
I hope this might be the right group to ask. I need to parse out in C language the XML of the following structure:
<BERTEST>
<NODE1>
<FREQ>666000000</FREQ>
<POWER>-82</POWER>
</NODE1>
<NODE1>
<FREQ>484000000</FREQ>
<POWER>-80</POWER>
</NODE2>
</BERTEST>
So I took the 'expat' library to do that (I've never dealt with XML before though), and tried to cutomize the example they ship with library (outline.c). What I can't quite understand is:
1) is my XML really can be called XML, or it's some sort of invalid? According to wikipedia page on XML, the valid document should look like this:
<name attribute="value">content</name>
while mine is a bit different
Your second <NODE1> should probably be <NODE2> (otherwise the start- and end-tags do not match up), but other than that it certainly is XML. You are free to choose (when designing a new XML format) whether you use an attribute or element to encode some information.
2) if anyway my xml document is correct, then how can I parse it with expat? What I need is upon occurences of FREQ and POWER tags to extract their values (i.e. 666000000 for FREQ or 082 for POWER in the above example).
So, I think I need to register callback function for start tags and try to do what I want in there. But how can I get the values of tags, which 'expat' functions to use? Or there's another, more simple way?
Expart reports the text through the `characters` callback. You have to setup a handler for it and accumulate the text reported to it; then process the text e.g. in the end_element handler. There is no direct way get to the text when using Expat.