Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/XML-Input/C/xml-input-1.c
Normal file
48
Task/XML-Input/C/xml-input-1.c
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
static void print_names(xmlNode *node)
|
||||
{
|
||||
xmlNode *cur_node = NULL;
|
||||
for (cur_node = node; cur_node; cur_node = cur_node->next) {
|
||||
if (cur_node->type == XML_ELEMENT_NODE) {
|
||||
if ( strcmp(cur_node->name, "Student") == 0 ) {
|
||||
xmlAttr *prop = NULL;
|
||||
if ( (prop = xmlHasProp(cur_node, "Name")) != NULL ) {
|
||||
printf("%s\n", prop->children->content);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
print_names(cur_node->children);
|
||||
}
|
||||
}
|
||||
|
||||
const char *buffer =
|
||||
"<Students>\n"
|
||||
" <Student Name=\"April\" Gender=\"F\" DateOfBirth=\"1989-01-02\" />\n"
|
||||
" <Student Name=\"Bob\" Gender=\"M\" DateOfBirth=\"1990-03-04\" />\n"
|
||||
" <Student Name=\"Chad\" Gender=\"M\" DateOfBirth=\"1991-05-06\" />\n"
|
||||
" <Student Name=\"Dave\" Gender=\"M\" DateOfBirth=\"1992-07-08\">\n"
|
||||
" <Pet Type=\"dog\" Name=\"Rover\" />\n"
|
||||
" </Student>\n"
|
||||
" <Student DateOfBirth=\"1993-09-10\" Gender=\"F\" Name=\"Émily\" />\n"
|
||||
"</Students>\n";
|
||||
|
||||
int main()
|
||||
{
|
||||
xmlDoc *doc = NULL;
|
||||
xmlNode *root = NULL;
|
||||
|
||||
doc = xmlReadMemory(buffer, strlen(buffer), NULL, NULL, 0);
|
||||
if ( doc != NULL ) {
|
||||
root = xmlDocGetRootElement(doc);
|
||||
print_names(root);
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
xmlCleanupParser();
|
||||
return 0;
|
||||
}
|
||||
54
Task/XML-Input/C/xml-input-2.c
Normal file
54
Task/XML-Input/C/xml-input-2.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <gadget/gadget.h>
|
||||
|
||||
LIB_GADGET_START
|
||||
|
||||
Main
|
||||
Assert( Arg_count == 2, end_input );
|
||||
Get_arg_str( xml_file, 1 );
|
||||
Assert( Exist_file(xml_file), file_not_exist );
|
||||
|
||||
char* xml = Load_string(xml_file);
|
||||
|
||||
ST_GETTAG field = Unparser( &xml, "Students");
|
||||
Assert ( field.content, fail_content );
|
||||
|
||||
while ( Occurs ("Student",field.content ) )
|
||||
{
|
||||
ST_GETTAG sub_field = Unparser( &field.content, "Student");
|
||||
|
||||
if(sub_field.attrib)
|
||||
{
|
||||
int i=0;
|
||||
Iterator up i [ 0: 1: sub_field.len ]
|
||||
{
|
||||
if ( strcmp(sub_field.name[i], "Name" )==0 )
|
||||
{
|
||||
Get_fn_let( sub_field.attrib[i], Str_tran( sub_field.attrib[i], "É","É" ) );
|
||||
/* OK... I must write the function that change this diabolic characters :D */
|
||||
Print "%s\n",sub_field.attrib[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Free tag sub_field;
|
||||
}
|
||||
|
||||
Free tag field;
|
||||
|
||||
/* Exceptions areas */
|
||||
Exception( fail_content ){
|
||||
Msg_red("Not content for \"Students\" field\n");
|
||||
}
|
||||
Free secure xml;
|
||||
|
||||
Exception( file_not_exist ){
|
||||
Msg_redf("File \"%s\" not found\n", xml_file);
|
||||
}
|
||||
Free secure xml_file;
|
||||
|
||||
Exception( end_input ){
|
||||
Msg_yellow("Use:\n RC_xml <xml_file.xml>");
|
||||
}
|
||||
|
||||
End
|
||||
9
Task/XML-Input/C/xml-input-3.c
Normal file
9
Task/XML-Input/C/xml-input-3.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<Students>
|
||||
<Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
|
||||
<Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
|
||||
<Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" />
|
||||
<Student Name="Dave" Gender="M" DateOfBirth="1992-07-08">
|
||||
<Pet Type="dog" Name="Rover" />
|
||||
</Student>
|
||||
<Student DateOfBirth="1993-09-10" Gender="F" Name="Émily" />
|
||||
</Students>
|
||||
Loading…
Add table
Add a link
Reference in a new issue