matthieu-labas / sxmlc Goto Github PK
View Code? Open in Web Editor NEWSimple, lightweight XML parser in C.
License: BSD 2-Clause "Simplified" License
Simple, lightweight XML parser in C.
License: BSD 2-Clause "Simplified" License
search->next is not being freed in XMLSearch_free().
if (free_next && search->next != NULL) {
(void)XMLSearch_free(search->next, true);
__free(search->next); <---- this line needs to be added
search->next = NULL;
}
Hello!
I've been trying out sxmlc and I'm encountering problems with using the xpath support. It could very well be that I'm just using it wrong! :)
I've got a simple xml file and I want to get at an element that I know where it is.
<?xml blah blah blah?>
<video>
<mode>1</mode>
</video>
I want to get at the text in the node. I'm trying XMLSearch_init_from_XPath() but I can't seem to find the correct format for the xpath text. I've tried "video/mode" and "/video/mode" but while the result returns 1 the contents of the nodes in the search have no text. Even if I put in a garbage path "adfladkfj" it still returns 1.
So, how to do I format the xpath string so that I can directly get the node?
Thanks!
Hi Matthieu,
Looks like commit 5cf1ce9 somehow breaks the search engine. It was working fine on previous commits, tested on 9fe2cdb (4.3.0) and afc5191 (4.2.10).
I'm submitting a simple XML, with the code that couldn't find a certain tag. I hope that this can help to resolve the inconvenient. Let me know if I can help out with something.
Best regards, D.
Hello Matthieu,
First of all thanks for this library. It look very good for reading existing XML, and creating XML documents from scratch.
There's some lack of support for modifying existing (loaded) XML documents. There's only one method to add a node, which is XMLNode_add_child(). This is fine when creating XML documents from scratch, but sometimes you need to add a node next to another one, right in that position, not at the end of all the children nodes of the father.
Have you ever thought about this feature? Can we expect to have it in a near future? Is there any current workaround to bypass this?
Thanks in advance. Best regards.
Hello Matthieu. While trying to use sxmlc on Linux, I found these 3 little things:
In
int XML_parse_attribute_to(const SXML_CHAR* str, int to, XMLAttribute* xmlattr)
maybe change
SXML_CHAR quote;
to
SXML_CHAR quote='\0'
(variable used without initialisation)
Maybe rename
#define sx_strdup __strdup
to
#define sx_strdup __sx_strdup
because it is already defined in /usr/include/bits/string2.h
Variable ch could be used without being initialised in read_line_alloc(). Maybe set it to EOF here:
if ((c = mgetc(in)) == EOF) { ch = EOF; break;
Hello @matthieu-labas ,
is it possible to opening XML from memory buffer or stream instead reading file on disk?
regards
Gilles Vollant
Hello Matthieu,
I keep on using this lib. I compiled the code with MinGW x64 and found out that i.e.: node->n_children
misleads the actual value of children number, it usually returns a very high number, i.e.: 108708416. Worth to mention that with MinGW x86 works perfect.
==5753== Conditional jump or move depends on uninitialised value(s)
==5753== at 0x40150E: XMLSearch_init (sxmlsearch.c:58)
==5753== by 0x4021C8: XMLSearch_init_from_XPath (sxmlsearch.c:385)
==5753== by 0x4013F3: main (main.cpp:12)
==5753== LEAK SUMMARY:
==5753== definitely lost: 85 bytes in 3 blocks
==5753== indirectly lost: 0 bytes in 0 blocks
==5753== possibly lost: 0 bytes in 0 blocks
==5753== still reachable: 0 bytes in 0 blocks
==5753== suppressed: 0 bytes in 0 blocks
Used test code:
#include "sxmlc.h"
#include "sxmlsearch.h"
int main() {
XMLSearch search;
SXML_CHAR* xpath2 = NULL;
const SXML_CHAR xpath[] = C2SX("/tagFather[@name, @id!='0', .='toto*']/tagChild[.='text', @attrib='value']");
if (XMLSearch_init_from_XPath(xpath, &search))
printf("%s\n %s\n", xpath, XMLSearch_get_XPath_string(&search, &xpath2, '\''));
else
printf("Error\n");
XMLSearch_free(&search, true);
return 0;
}
why can't I find all tags.. what can be problem ..
void display_recursive_children_content(XMLNode*source , int children_count, char* names) {
for (int i = 0; i < source->n_children; i++) {
XMLNode *child = source->children[i];
int new_children = child->n_children;
if (new_children > 0) {
char s[100];
if (child->n_attributes == 0)
{
strcat(names, " ");
strcat(names, child->tag);
//printf(" n%s", names);
//printf(" %s", child->text);
}
else
printf(" \n %s", child->tag);
for (int j = 0; j < child->n_attributes; j++)
{
strcpy(s, names);
strcat(s, " ");
strcat(s, child->attributes[j].name);
strcat(s, ": ");
strcat(s, child->attributes[j].value);
printf(" %s", child->attributes[j].name);
printf(" %s", child->attributes[j].value);
}
display_recursive_children_content(child, new_children, s);
}
else {
printf(" %s", names);
printf(" %s", child->tag);
printf(" %s", child->text);
}
}
}
Originally posted by @embbo in #16 (comment)
Hi, it looks like html2str is not called on text content, only on attributes. Is this the expected behavior?
Describe the bug
A bad xml file which can lead XMLDoc_parse_file_DOM to segmentation fault.
Poc here :
segv1.zip
To Reproduce
// driver.c
#include "sxmlc.h"
#include "sxmlsearch.h"
int main(int argc, char** argv){
if(argc!=2) return 0;
XMLDoc doc;
XMLDoc_init(&doc);
XMLDoc_parse_file_DOM(argv[1], &doc);
XMLDoc_free(&doc);
return 0;
}
$ ./driver ./segv1
Expected behavior
Parse the xml file without segmentation fault because segmentation fault can cause a Denial of Service (Dos).
Environment (please complete the following information):
Additional context
ASAN says:
$ ./driver segv1
ASAN:DEADLYSIGNAL
=================================================================
==127014==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f568dd6ee1a bp 0x7ffd78b77380 sp 0x7ffd78b76ae0 T0)
==127014==The signal is caused by a READ memory access.
==127014==Hint: address points to the zero page.
#0 0x7f568dd6ee19 (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x59e19)
#1 0x7f568daf602b in DOMXMLDoc_node_end /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1600
#2 0x7f568dafbb45 in _parse_data_SAX /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1515
#3 0x7f568daf85cd in XMLDoc_parse_file_SAX /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1780
#4 0x7f568dafe74c in XMLDoc_parse_file_DOM_text_as_nodes /home/ubuntu/some_c_test/sxmlc/src/sxmlc.c:1831
#5 0x55ce76aa2d99 in main /home/ubuntu/some_c_test/sxmlc/fuzz/driver.cpp:10
#6 0x7f568d70bc86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
#7 0x55ce76aa2e89 in _start (/home/ubuntu/some_c_test/sxmlc/fuzz/driver+0xe89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x59e19)
==127014==ABORTING
@matthieu-labas
I am trying to find specific data from xml string, I tried myself but i faild . do you have any idea or clue how can I do that ..
for example I have this string ...
<UAVariable BrowseName="1:DeviceName" DataType="String" NodeId="ns=1;i=2005" ParentNodeId="ns=1;i=2001"> <DisplayName>DeviceName</DisplayName> <Description>DeviceName</Description> <References> <Reference IsForward="false" ReferenceType="HasComponent">ns=1;i=2001</Reference> <Reference ReferenceType="HasTypeDefinition">i=63</Reference> </References> <Value> <uax:String>MyName</uax:String> </Value> </UAVariable>
I can read this sting but I want to read values of BrowseName, DataType, NodeId .... which are 1:DeviceName ..String and ns=1;i=2005 repectively
Like Key --> value
Hi, I am using sxmlc Parsor which is really good for my Micro controller, but my question is it possible if I can parsor tag by tag instead of whole xml. beacuse my micro controller ihave low memory ..
for example .
Ist it just copy these Tags
<UAObject NodeId="i=20002" BrowseName="0:Control" ParentNodeId="i=85"> ..... ...... .... </UAObject>
than next tags
... ... ...Hi all, I just started sxmlc with the example and it works perfectly but I want to read an xml string NOT a file from out side..any clue how can i do that .. like this
string xml = "mo<daily dayFrequency=""1"" />2012-10-31T10:00:00Z";
Regards
Describe the bug
A bad xml file which can lead XMLDoc_parse_file_DOM to segmentation fault.
Poc here :
segv2.zip
To Reproduce
// driver.c
#include "sxmlc.h"
#include "sxmlsearch.h"
int main(int argc, char** argv){
if(argc!=2) return 0;
XMLDoc doc;
XMLDoc_init(&doc);
XMLDoc_parse_file_DOM(argv[1], &doc);
XMLDoc_free(&doc);
return 0;
}
$ ./driver ./segv2
Expected behavior
Parse the xml file without segmentation fault because segmentation fault can cause a Denial of Service (Dos).
Environment (please complete the following information):
Additional context
ASAN says:
$ ./driver segv2
ASAN:DEADLYSIGNAL
=================================================================
==30894==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000002 (pc 0x7f0ae710f525 bp 0x7ffda877adb0 sp 0x7ffda877acc0 T0)
==30894==The signal is caused by a WRITE memory access.
==30894==Hint: address points to the zero page.
#0 0x7f0ae710f524 in freadBOM /home/chan/some_c_test/sxmlc/src/sxmlc.c:2294
#1 0x7f0ae710e4be in XMLDoc_parse_file_SAX /home/chan/some_c_test/sxmlc/src/sxmlc.c:1760
#2 0x7f0ae711474c in XMLDoc_parse_file_DOM_text_as_nodes /home/chan/some_c_test/sxmlc/src/sxmlc.c:1831
#3 0x564f36dfdd99 in main /home/chan/some_c_test/sxmlc/fuzz/driver.cpp:10
#4 0x7f0ae6d21c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
#5 0x564f36dfde89 in _start (/home/chan/some_c_test/sxmlc/fuzz/driver+0xe89)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/chan/some_c_test/sxmlc/src/sxmlc.c:2294 in freadBOM
==30894==ABORTING
Hi i am reading from eeprom and i get string without any problem . but when i parse, it doesn't recognize the string .. its like this
char buffer[1024];
printf buffer :
but if i declare string in same fiuntion it works fine.
char buffer[] = "\n"............
XMLDoc doc;
XMLDoc_init(&doc);
XMLDoc_parse_buffer_DOM(buffer, "test1", &doc);
XMLNode* root;
root = doc.nodes[doc.i_root];
char* root_name = (char*)malloc(strlen(root->tag));
strcpy(root_name, root->tag);
display_recursive_children_content(root, root->n_children, root->tag);
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.