Hi there,
I am struggling to write a piece of code that would parse a simple
xml file. I was wondering if there are good example (pattern?) to use
when dealing with nested xml elements.
For instance my xml looks like (*), with only one level of nesting.
AFAIK I need to do the book keeping myself esp. when reading the
CharacterData so that it is associated to the correct entry.
All I need to do is load the dict in some kind of matching C++
structure. This is not my homework, I am simply trying to use some
kind of pattern so that my code is readable later on.
Thanks
-Mathieu
(*)
<?xml version="1.0"?>
<dict>
<entry key="1" value="a">
<desc>blue</desc>
</entry>
<entry key="2" value="b">
<desc>red</desc>
</entry>
<entry key="3" value="c">
<desc>green</desc>
<entry key="2" value="d">
<desc>purple</desc>
</entry>
<entry key="4" value="e">
<desc>yellow</desc>
</entry>
<entry key="5" value="f">
<desc>orange</desc>
</entry>
</entry>
</dict> 2 1533
* mathieu wrote in comp.text.xml:
I am struggling to write a piece of code that would parse a simple xml file. I was wondering if there are good example (pattern?) to use when dealing with nested xml elements.
For instance my xml looks like (*), with only one level of nesting. AFAIK I need to do the book keeping myself esp. when reading the CharacterDat a so that it is associated to the correct entry.
All I need to do is load the dict in some kind of matching C++ structure. This is not my homework, I am simply trying to use some kind of pattern so that my code is readable later on.
Well, a simple pattern is to use a stack, on start_element you push and
on end_element you pop; character data, comments, et al. are then always
associated with the element on top of the stack. Often you'll also have
an additional state variable to recall where you are and what you are
looking for, e.g. keeping track of preceding children of an element. On
the web are plenty of examples using expat, if those do not help, you'd
need to ask a more specific question.
--
Björn Höhrmann · mailto:bj****@h oehrmann.de · http://bjoern.hoehrmann.de
On Aug 19, 11:29*am, Bjoern Hoehrmann <bjo...@hoehrma nn.dewrote:
* mathieu wrote in comp.text.xml:
*I am struggling to write a piece of code that would parse a simple
xml file. I was wondering if there are good example (pattern?) to use
when dealing with nested xml elements.
*For instance my xml looks like (*), with only one level of nesting.
AFAIK I need to do the book keeping myself esp. when reading the
CharacterData so that it is associated to the correct entry.
*All I need to do is load the dict in some kind of matching C++
structure. This is not my homework, I am simply trying to use some
kind of pattern so that my code is readable later on.
Well, a simple pattern is to use a stack, on start_element you push and
on end_element you pop; character data, comments, et al. are then always
associated with the element on top of the stack. Often you'll also have
an additional state variable to recall where you are and what you are
looking for, e.g. keeping track of preceding children of an element. On
the web are plenty of examples using expat, if those do not help, you'd
need to ask a more specific question.
The only examples I found using expat are extremely simple. Do you
have a link in mind, or simply the google query you tried.
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Will Stuyvesant |
last post by:
There seems to be no XML parser that can do validation in
the Python Standard Libraries. And I am stuck with Python
2.1.1. until my web master upgrades (I use Python for
CGI). I know pyXML has validating parsers, but I can not
compile things on the (unix) webserver. And even if I
could, the compiler I have access to would be different
than what was used to compile python for CGI.
I need to write a CGI script that does XML validation...
|
by: Armin Steinhoff |
last post by:
Hi all,
is it possible to get the name of an empty element specified
by <element/> ... the expat parser seems only to recognize
the <element></element> form
Regards
Armin
|
by: David |
last post by:
Hi,
I'm trying to parse an xml file and am a bit confused. I have created my
class XmlParser.
Also I have 3 other questions.
1-How to the GetAttribute to search for the value of a specific pattern ?
I want to get the value of the Count tag.
2- My file does not contain the standalone header ? How can I deal with
|
by: Sridhar |
last post by:
HI,
I am beginner to Expat and currently started learning.
What I understood about Expat is
Expat is freeware
It is good XML Parser
Provides C-API
|
by: horndude77 |
last post by:
Ok, this might be for a web designing group, but here's my problem. I'm
trying to make a web page with tabs which you can navigate between
without the page reloading. I have one set of tabs working great, but
when I add nested tabs there is a problem with the 'visibility' not
being inherited and some parts stay visible in the sub-tabs. Sorry if
this is unclear.
Here's how I have it layed out: I have a <span> for each content
section of...
| |
by: Maarten Verhage |
last post by:
Hi All,
I've made a modified version of the Expat elements.c example. What I
want the program to do is to recognize a hardcoded
element-name/tag-name and then execute some code which has access to
the data(e.g. "Maarten Verhage" in XML file).
The current situation (problem) is:
1. The XML parser calls the function startElement when it finds a tag,
|
by: dwelch91 |
last post by:
Hi, c.l.p.'ers-
I am having a problem with the import of xml.parsers.expat that has
gotten me completely stumped. I have two programs, one a PyQt program
and one a command line (text) program that both eventually call the
same code that imports xml.parsers.expat. Both give me different
results...
The code that gets called is (print statements have been added for
debugging):
|
by: =?Utf-8?B?SmVyZW15X0I=?= |
last post by:
I am working on an order entry program and have a question related to
deserializing nodes with nested elements.
The purchase order contains multiple line items which I select using an
XmlNodeList. I am trying to deserialize the nodes using a foreach as follows:
foreach(XmlNode lineItem in LineItemsNodeList)
An abbreviated example of the nested lineItem node looks like this:
|
by: vadlapatlahari |
last post by:
Hi,
I get the following error with Expat while configuring my application server. Can anyone suggest a solution?
When i do an ldd, i get the following :
$ldd Expat.so
Expat.so needs:
/usr/lib/libc.a(shr.o)
Cannot find /unix --- Is there a problem here?
/usr/lib/libcrypt.a(shr.o)
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |