File: document_create.c

package info (click to toggle)
gxml 0.20.4%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,364 kB
  • sloc: xml: 131,277; ansic: 786; javascript: 328; python: 88; makefile: 35; sh: 11
file content (55 lines) | stat: -rw-r--r-- 2,125 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <gxml/gxml.h>

int main () {
  GXmlDocument *doc;

  doc = gxml_document_new ();

  /* <bookElement></bookElement> */
  GXmlElement *elem;
  elem = gxml_document_create_element (doc, "bookElement");
  printf ("Book element: %s\n", gxml_node_to_string (GXML_NODE (elem), FALSE, 0));

  GXmlDocumentFragment *docfragment;
  docfragment = gxml_document_create_document_fragment (doc);
  printf ("Document fragment: %s\n", gxml_node_to_string (GXML_NODE (docfragment), FALSE, 0));

  /* <book>Between the book tags is text!</book> */
  GXmlText *text;
  text = gxml_document_create_text_node (doc, "Between the book tags is text!");
  printf ("Text node: %s\n", gxml_node_to_string (GXML_NODE (text), FALSE, 0));

  /* <book><!-- comment: I really like this book -->The fault in our stars</book> */
  GXmlComment *comment;
  comment = gxml_document_create_comment (doc, "comment: I really like this book");
  printf ("Comment: %s\n", gxml_node_to_string (GXML_NODE (comment), FALSE, 0));

  /* <![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");
  printf ("CDATA section: %s\n", gxml_node_to_string (GXML_NODE (cdata), FALSE, 0));

  /* <?xml href="style.xsl" type="text/xml"?> */
  GXmlProcessingInstruction *pi;
  pi = gxml_document_create_processing_instruction (doc, "xml", "href=\"style.xsl\" type=\"text/xml\"");
  printf ("Processing Instruction: %s\n", gxml_node_to_string (GXML_NODE (pi), FALSE, 0));

  /* <element id=""> */
  GXmlAttr *attr;
  attr = gxml_document_create_attribute (doc, "id");
  printf ("Attribute: %s\n", gxml_node_to_string (GXML_NODE (attr), FALSE, 0));

  /* &apos;   (for an apostrophe, ') */
  GXmlEntityReference *entref;
  entref = gxml_document_create_entity_reference (doc, "apos");
  printf ("Entity reference: %s\n", gxml_node_to_string (GXML_NODE (entref), FALSE, 0));

  gxml_node_append_child (GXML_NODE (doc), GXML_NODE (elem));

  g_object_unref (pi);
  g_object_unref (entref);
  g_object_unref (attr);
  g_object_unref (doc);

  return 0;
}