lxfontes / ezxml Goto Github PK
View Code? Open in Web Editor NEWezxml - XML parser
Home Page: http://ezxml.sourceforge.net/
License: MIT License
ezxml - XML parser
Home Page: http://ezxml.sourceforge.net/
License: MIT License
ezXML - XML Parsing C Library version 0.8.5 ezXML is a C library for parsing XML documents inspired by simpleXML for PHP. As the name implies, it's easy to use. It's ideal for parsing XML configuration files or REST web service responses. It's also fast and lightweight (less than 20k compiled). The latest verions is available here: http://prdownloads.sf.net/ezxml/ezxml-0.8.6.tar.gz?download Example Usage Given the following example XML document: <?xml version="1.0"?> <formula1> <team name="McLaren"> <driver> <name>Kimi Raikkonen</name> <points>112</points> </driver> <driver> <name>Juan Pablo Montoya</name> <points>60</points> </driver> </team> </formula1> This code snippet prints out a list of drivers, which team they drive for, and how many championship points they have: ezxml_t f1 = ezxml_parse_file("formula1.xml"), team, driver; const char *teamname; for (team = ezxml_child(f1, "team"); team; team = team->next) { teamname = ezxml_attr(team, "name"); for (driver = ezxml_child(team, "driver"); driver; driver = driver->next) { printf("%s, %s: %s\n", ezxml_child(driver, "name")->txt, teamname, ezxml_child(driver, "points")->txt); } } ezxml_free(f1); Alternately, the following would print out the name of the second driver on the first team: ezxml_t f1 = ezxml_parse_file("formula1.xml"); printf("%s\n", ezxml_get(f1, "team", 0, "driver", 1, "name", -1)->txt); ezxml_free(f1); The -1 indicates the end of the argument list. That's pretty much all there is to it. Complete API documentation can be found in ezxml.h. Known Limitations - ezXML is not a validating parser - Loads the entire XML document into memory at once and does not allow for documents to be passed in a chunk at a time. Large XML files can still be handled though through ezxml_parse_file() and ezxml_parse_fd(), which use mmap to map the file to a virtual address space and rely on the virtual memory system to page in data as needed. - Does not currently recognize all possible well-formedness errors. It should correctly handle all well-formed XML documents and will either ignore or halt XML processing on well-formedness errors. More well-formedness checking will be added in subsiquent releases. - In making the character content of tags easy to access, there is no way provided to keep track of the location of sub tags relative to the character data. Example: <doc>line one<br/> line two</doc> The character content of the doc tag is reported as "line one\nline two", and <br/> is reported as a sub tag, but the location of <br/> within the character data is not. The function ezxml_toxml() will convert an ezXML structure back to XML with sub tag locations intact. Licensing ezXML was written by Aaron Voisine <[email protected]> and is distributed under the terms of the MIT license, described in license.txt.
When passing NULL to ezxml_set_attr I am getting a segfault, even though in file itself it says that passing NULL would remove tag.
Hope to hear from you soon,
Thanks in advance.
Compilation warning arise in ezxml.c for gcc compiler to parse an inline expression of condition which breaks a while loop.
The code snippet triggering the warning took place in line 364, inside function ezxml_internal_dtd()
, which aims to parse default attributes such as .
The environment is under CentOS Linux release 7.9.2009 (Core), with gcc (GCC) 7.3.0.
Compilation rules were defined ias below, with ezxml.h located in ${PROJECT_BINARY_DIR} and ezxml.c in the same directory with CMakeList.txt.
project(APP C)
include_directories(${PROJECT_BINARY_DIR})
# source files
set(CLI_SRC ezxml.c)
add_executable(APP ${CLI_SRC})
...
gcc shows warning as below:
[ 85%] Building C object cli/CMakeFiles/ezxml.c.o
/home/cli/ezxml.c: In function 'ezxml_internal_dtd':
/home/cli/ezxml.c:364:26: warning: operation on 's' may be undefined [-Wsequence-point]
while (*(n = ++s + strspn(s, EZXML_WS)) && *n != '>') {
^
My suggestion would be removing the inline condition expression, and adopting an multi-line expression instead.
Such as
while (*n != '>') {
++s;
if (*(n = s + strspn(s, EZXML_WS)) == 0) { break; }
...
/label ~bug ~reproduced ~needs-investigation
I suggest inserting these lines in ezxml.c
#ifdef _WIN32
#define EZXML_NOMMAP
#endif
Please
Compilation warning arise in ezxml.c
for gcc-7 compiler to compare between signed integer(-1
) and unsigned variable (root->len
) within function void ezxml_free(ezxml_t xml)
.
It raises an -Wsign-compare warning in gcc-7.
The environment is under CentOS Linux release 7.9.2009 (Core), with gcc (GCC) 7.3.0.
Compilation rules were defined as below, with ezxml.h located in ${PROJECT_BINARY_DIR} and ezxml.c in the same directory with CMakeList.txt. ( same with #6 )
project(APP C)
include_directories(${PROJECT_BINARY_DIR})
# source files
set(CLI_SRC ezxml.c)
add_executable(APP ${CLI_SRC})
...
gcc shows warning as below:
[ 85%] Building C object cli/CMakeFiles/ezxml.c.o
/home/cli/ezxml.c: In function 'ezxml_free':
/home/cli/ezxml.c:813:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (root->len == -1) free(root->m);
^
My suggestion would be add a type conversion such as
if (root->len == (unsigned int)-1) free(root->m); // malloced xml data
Instead of
if (root->len == -1) free(root->m); // malloced xml data
/label ~bug ~reproduced ~needs-investigation
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.