XML/Input: Difference between revisions

added C
(added C)
Line 20:
 
=={{header|ActionScript}}==
<lang actionscript>
package
{
Line 43:
}
}
</lang>
</actionscript>
 
 
=={{header|C}}==
 
{{libheader|libxml2}}
 
<lang c>#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\" />\n"
"<Student Name=\"Bob\" />\n"
"<Student Name=\"Chad\" />\n"
"<Student Name=\"Dave\" />\n"
"<Student Name=\"Emily\" />\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;
}</lang>
 
 
=={{header|J}}==
Line 73 ⟶ 126:
 
=={{header|OCaml}}==
<lang ocaml>
<pre>
# #directory "+site-lib/xml-light" (* or maybe just "+xml-light" *) ;;
# #load "xml-light.cma" ;;
Line 96 ⟶ 149:
Emily
- : unit = ()
</prelang>
=={{header|Visual Basic .NET}}==
<lang lang="vbnet">Dim xml = <Students>