XML/Input: Difference between revisions
Content added Content deleted
Line 1,056: | Line 1,056: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{libheader|LibXML}} |
==={{libheader|LibXML}}=== |
||
{{uses from|Library|libxml|component1=xmlDoc|component2=xmlNode|component3=xmlReadMemory|component4=xmlDocGetRootElement|component5=xmlFreeDoc|component6=xmlCleanupParser|component7=xmlNode|component8=XML_ELEMENT_NODE|component9=xmlAttr|component10=xmlHasProp}} |
{{uses from|Library|libxml|component1=xmlDoc|component2=xmlNode|component3=xmlReadMemory|component4=xmlDocGetRootElement|component5=xmlFreeDoc|component6=xmlCleanupParser|component7=xmlNode|component8=XML_ELEMENT_NODE|component9=xmlAttr|component10=xmlHasProp}} |
||
{{uses from|Library|C Runtime|component1=printf}} |
{{uses from|Library|C Runtime|component1=printf}} |
||
Line 1,107: | Line 1,107: | ||
return 0; |
return 0; |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
==={{libheader|Gadget}}=== |
|||
<p>Gadget is a library for strings handler, not XML handler. But...</p> |
|||
<syntaxhighlight lang="c"> |
|||
#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 |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
$ ./tests/RC_xml xml_data.xml |
|||
April |
|||
Bob |
|||
Chad |
|||
Dave |
|||
Émily |
|||
</pre> |
|||
<p>File: xml_data.xml:</p |
|||
<pre> |
|||
<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> |
|||
</pre> |
|||
=={{header|C sharp}}== |
=={{header|C sharp}}== |