Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #715
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Subject | Failure to extract information using mini-XML v2.8 |
| Newsgroups | comp.os.linux.development.apps |
| Organization | The Pitcher Digital Freehold |
| Message-ID | <Sl86v.121102$nm4.66014@fx27.iad> (permalink) |
| Date | 2014-04-24 09:30 -0400 |
While using miniXML v2.8 (http://www.msweet.org/projects.php?Z3) to read and
process an XML document in a small C program, I came across a problem that
I cannot surmount.
While it is more likely that I'm just not using the API correctly, it may be
that I've uncovered a bug with miniXML. I've reported my problem, with a
suitable test case, to the author, in a bug report.
However, while I wait for a response, I want to hear from other miniXML
users, to see if I've just mis-read or mis-interpreted the API
documentation.
For my demo, I have a dead simple XML document:
<?xml version="1.0" encoding="utf-8"?><document>Hello, World</document>
The goal of the demo is to extract and print the text contents of the
<document> entity, and it's output /should be/
Success: "Hello, World"
This simple demo program looks like...
#include <stdio.h>
#include <stdlib.h>
#include <mxml.h>
int main(void)
{
int rc = EXIT_FAILURE;
mxml_node_t *xml, *doc;
const char *text;
xml = mxmlLoadFile(NULL,stdin,MXML_TEXT_CALLBACK);
doc = mxmlFindElement(xml,xml,"document",NULL,NULL,MXML_DESCEND_FIRST);
text = mxmlGetText(doc,NULL);
if (text)
{
printf("Success: \"%s\"\n",text);
rc = EXIT_SUCCESS;
}
else puts("Fail");
return rc;
}
And here is a trial run and it's output...
$ cat document.xml
<?xml version="1.0" encoding="utf-8"?><document>Hello, World</document>
$ cat document.xml | consumer_s
Fail
$ consumer_s <document.xml
Fail
$
Outside of the obvious error checking, what (if anything) am I doing wrong?
If I read the documentation correctly, the mxmlGetText() call /should/
return a pointer to the text attached to the node that mxmlFindElement()
returned. But, it doesn't. It returns NULL (or the functional equivalent
thereof).
A little more complex code shows that, indeed the mxmlLoadFile() function
loaded the example XML document into a valid miniXML tree (presumably as
TEXT nodes, as specified by the MXML_TEXT_CALLBACK option), and that the
mxmlFindElement() call did indeed locate the "<document>" node.
The miniXML documentation on the mxmlGetText() function reads
> mxmlGetText
> Get the text value for a node or its first child.
> const char *mxmlGetText (
> mxml_node_t *node,
> int *whitespace
> );
> Parameters
> node
> Node to get
> whitespace
> 1 if string is preceded by whitespace, 0
> otherwise
> Return Value
> Text string or NULL
> Discussion
> NULL is returned if the node (or its first child) is not a
> text node. The "whitespace" argument can be NULL.
>
What, if anything, am I doing wrong?
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Back to comp.os.linux.development.apps | Previous | Next — Next in thread | Find similar
Failure to extract information using mini-XML v2.8 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-04-24 09:30 -0400
Re: Failure to extract information using mini-XML v2.8 Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-04-24 19:04 +0100
Re: Failure to extract information using mini-XML v2.8 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-04-24 15:16 -0400
Re: Failure to extract information using mini-XML v2.8 Rainer Weikusat <rweikusat@mobileactivedefense.com> - 2014-04-24 20:45 +0100
Re: Failure to extract information using mini-XML v2.8 Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-04-24 16:02 -0400
csiph-web