From 35a201cc8ef0c3f5b2df88d2e528aabee1048348 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 30 Apr 2021 18:47:09 +0200 Subject: Initial/Final commit --- libxml2-2.9.10/doc/tutorial/ar01s03.html | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 libxml2-2.9.10/doc/tutorial/ar01s03.html (limited to 'libxml2-2.9.10/doc/tutorial/ar01s03.html') diff --git a/libxml2-2.9.10/doc/tutorial/ar01s03.html b/libxml2-2.9.10/doc/tutorial/ar01s03.html new file mode 100644 index 0000000..cd28fff --- /dev/null +++ b/libxml2-2.9.10/doc/tutorial/ar01s03.html @@ -0,0 +1,47 @@ +Parsing the file

Parsing the file

+Parsing the file requires only the name of the file and a single + function call, plus error checking. Full code: Appendix C, Code for Keyword Example

+

+        1 xmlDocPtr doc;
+	2 xmlNodePtr cur;
+
+	3 doc = xmlParseFile(docname);
+	
+	4 if (doc == NULL ) {
+		fprintf(stderr,"Document not parsed successfully. \n");
+		return;
+	}
+
+	5 cur = xmlDocGetRootElement(doc);
+	
+	6 if (cur == NULL) {
+		fprintf(stderr,"empty document\n");
+		xmlFreeDoc(doc);
+		return;
+	}
+	
+	7 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
+		fprintf(stderr,"document of the wrong type, root node != story");
+		xmlFreeDoc(doc);
+		return;
+	}
+
+    

+

1

Declare the pointer that will point to your parsed document.

2

Declare a node pointer (you'll need this in order to + interact with individual nodes).

4

Check to see that the document was successfully parsed. If it + was not, libxml will at this point + register an error and stop. +

[Note]Note

+One common example of an error at this point is improper + handling of encoding. The XML standard requires + documents stored with an encoding other than UTF-8 or UTF-16 to + contain an explicit declaration of their encoding. If the + declaration is there, libxml will + automatically perform the necessary conversion to UTF-8 for + you. More information on XML's encoding + requirements is contained in the standard.

+

5

Retrieve the document's root element.

6

Check to make sure the document actually contains something.

7

In our case, we need to make sure the document is the right + type. "story" is the root type of the documents used in this + tutorial.

+ +

-- cgit v1.2.3