Skip to content
Commit 152e5267 authored by Richard Schwarting's avatar Richard Schwarting
Browse files

examples/c: add document_factory.c, remove a comment from document_properties.c

parent 26c121c3
No related branches found
No related tags found
No related merge requests found
CC=gcc
CFLAGS=`pkg-config --cflags gxml gio-2.0` -g -Wall
LDFLAGS=`pkg-config --libs gxml gio-2.0`
PROGS=create_document create_document_minimal create_document_from_string create_document_from_file create_document_from_path save_document_to_path save_document_to_stream
PROGS=document_create document_create_minimal document_create_from_string document_create_from_file document_create_from_path document_save_to_path document_save_to_stream document_properties document_factory
all: $(PROGS)
......
#include <gxml/gxml.h>
int main () {
GXmlDocument *doc;
doc = gxml_document_new ();
/* <bookElement> */
GXmlElement *elem;
elem = gxml_document_create_element (doc, "tagname");
GXmlDocumentFragment *docfragment;
docfragment = gxml_document_create_document_fragment (doc);
/* <book>Between the book tags is text!</book> */
GXmlText *text;
text = gxml_document_create_text_node (doc, "Here is some text in an XML document");
/* <book><!-- comment: I really like this one -->The fault in our stars</book> */
GXmlComment *comment;
comment = gxml_document_create_comment (doc, "Here is an XML comment");
/* <![CDATA[non-XML data like code or special entities]]> */
GXmlCDATASection *cdata;
cdata = gxml_document_create_cdata_section (doc, "non-XML data like code or special entities");
/* <?xml href="style.xsl" type="text/xml"?> */
GXmlProcessingInstruction *pi;
pi = gxml_document_create_processing_instruction (doc, "xml", "href=\"style.xsl\" type=\"text/xml\"");
/* <element id=""> */
GXmlAttr *attr;
attr = gxml_document_create_attribute (doc, "id");
/* &apos; (for an apostrophe, ') */
GXmlEntityReference *entref;
entref = gxml_document_create_entity_reference (doc, "apos");
gxml_node_append_child (GXML_NODE (doc), GXML_NODE (elem));
g_object_unref (elem);
g_object_unref (pi);
g_object_unref (entref);
g_object_unref (attr);
g_object_unref (docfragment);
g_object_unref (text);
g_object_unref (comment);
g_object_unref (cdata);
g_object_unref (doc);
return 0;
}
......@@ -8,7 +8,6 @@ int main () {
xml = "<?xml version=\"1.0\"?><!DOCTYPE bookshelf><Bookshelf><Owner fullname=\"John Green\"/><Books><Book author=\"John Green\" title=\"The Fault in Our Stars\"/><Book author=\"Jane Austen\" title=\"Pride &amp; Prejudice\"/><Book author=\"J.D. Salinger\" title=\"Nine Stories\"/></Books></Bookshelf>";
doc = gxml_document_new_from_string (xml);
// should be "#document"
const gchar *doc_node_name;
doc_node_name = gxml_node_get_node_name (GXML_NODE (doc));
printf ("A document's node_name is: %s (which should always be '#document')\n\n", doc_node_name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment