diff --git a/ChangeLog b/ChangeLog index 68e583de..bfba42c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sun Dec 15 21:27:30 MST 2002 John Fleck + + * doc/tutorial/xmltutorial.xml + * doc/tutorial/includekeyword.c + * doc/tutorial/includegetattribute.c + plus generated html and pdf + Adding fix from Niraj Tolia to tutorial to properly free memory. + + Mon Dec 16 00:34:25 CET 2002 Daniel Veillard * xmlreader.c include/libxml/xmlreader.h doc/libxml2-api.xml: added diff --git a/doc/tutorial/apb.html b/doc/tutorial/apb.html index a9ace0bf..19b4cebc 100644 --- a/doc/tutorial/apb.html +++ b/doc/tutorial/apb.html @@ -10,11 +10,14 @@ void parseStory (xmlDocPtr doc, xmlNodePtr cur) { + xmlChar *key; cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) { - printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); - } + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf("keyword: %s\n", key); + xmlFree(key); + } cur = cur->next; } return; @@ -30,7 +33,6 @@ parseDoc(char *docname) { if (doc == NULL ) { fprintf(stderr,"Document not parsed successfully. \n"); - xmlFreeDoc(doc); return; } diff --git a/doc/tutorial/ape.html b/doc/tutorial/ape.html index f473044c..9dc363ca 100644 --- a/doc/tutorial/ape.html +++ b/doc/tutorial/ape.html @@ -10,14 +10,17 @@ void getReference (xmlDocPtr doc, xmlNodePtr cur) { + xmlChar *uri; cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) { - printf("uri: %s\n", xmlGetProp(cur, "uri")); - } + uri = xmlGetProp(cur, "uri"); + printf("uri: %s\n", uri); + xmlFree(uri); + } cur = cur->next; } - return; + return; } diff --git a/doc/tutorial/apg.html b/doc/tutorial/apg.html index bdef9712..3bd6e7a4 100644 --- a/doc/tutorial/apg.html +++ b/doc/tutorial/apg.html @@ -1,5 +1,5 @@ -G. Acknowledgements

G. Acknowledgements

A number of people have generously offered feedback, code and +G. Acknowledgements

G. Acknowledgements

A number of people have generously offered feedback, code and suggested improvements to this tutorial. In no particular order: -

Daniel Veillard
Marcus Labib Iskander
Christopher R. Harris
Igor Zlatkovic

+

Daniel Veillard
Marcus Labib Iskander
Christopher R. Harris
Igor Zlatkovic
Niraj Tolia

diff --git a/doc/tutorial/ar01s03.html b/doc/tutorial/ar01s03.html index eead7a86..a90e3174 100644 --- a/doc/tutorial/ar01s03.html +++ b/doc/tutorial/ar01s03.html @@ -32,14 +32,14 @@ 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 +

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.

+ 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.

diff --git a/doc/tutorial/ar01s07.html b/doc/tutorial/ar01s07.html index 9335237f..fe0bd7cd 100644 --- a/doc/tutorial/ar01s07.html +++ b/doc/tutorial/ar01s07.html @@ -11,14 +11,17 @@ void getReference (xmlDocPtr doc, xmlNodePtr cur) { + xmlChar *uri; cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) { - 1 printf("uri: %s\n", xmlGetProp(cur, "uri")); - } + 1 uri = xmlGetProp(cur, "uri"); + printf("uri: %s\n", uri); + xmlFree(uri); + } cur = cur->next; } - return; + return; }

@@ -26,10 +29,10 @@ getReference (xmlDocPtr doc, xmlNodePtr cur) { The key function is xmlGetProp, which returns an xmlChar containing the attribute's value. In this case, we just print it out. -

[Note]Note

+

Note

If you are using a DTD that declares a fixed or default value for the attribute, this function will retrieve it. -

+

diff --git a/doc/tutorial/ar01s08.html b/doc/tutorial/ar01s08.html index 509c8d56..70bb1654 100644 --- a/doc/tutorial/ar01s08.html +++ b/doc/tutorial/ar01s08.html @@ -18,14 +18,14 @@ different character formats with ability to convert from any to any. While the actual number of supported formats varies between implementations, every iconv implementation is almost guaranteed to - support every format anyone has ever heard of.

[Warning]Warning

A common mistake is to use different formats for the internal data + support every format anyone has ever heard of.

Warning

A common mistake is to use different formats for the internal data in different parts of one's code. The most common case is an application that assumes ISO-8859-1 to be the internal data format, combined with libxml, which assumes UTF-8 to be the internal data format. The result is an application that treats internal data differently, depending on which code section is executing. The one or the other part of code will then, naturally, misinterpret the data. -

This example constructs a simple document, then adds content provided +

This example constructs a simple document, then adds content provided at the command line to the document's root element and outputs the results to stdout in the proper encoding. For this example, we use ISO-8859-1 encoding. The encoding of the string input at the command diff --git a/doc/tutorial/includegetattribute.c b/doc/tutorial/includegetattribute.c index 17f5a2f4..b2b74711 100644 --- a/doc/tutorial/includegetattribute.c +++ b/doc/tutorial/includegetattribute.c @@ -8,14 +8,17 @@ void getReference (xmlDocPtr doc, xmlNodePtr cur) { + xmlChar *uri; cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) { - printf("uri: %s\n", xmlGetProp(cur, "uri")); - } + uri = xmlGetProp(cur, "uri"); + printf("uri: %s\n", uri); + xmlFree(uri); + } cur = cur->next; } - return; + return; } diff --git a/doc/tutorial/includekeyword.c b/doc/tutorial/includekeyword.c index d62d0a53..e9bb4672 100644 --- a/doc/tutorial/includekeyword.c +++ b/doc/tutorial/includekeyword.c @@ -8,11 +8,14 @@ void parseStory (xmlDocPtr doc, xmlNodePtr cur) { + xmlChar *key; cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) { - printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); - } + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + printf("keyword: %s\n", key); + xmlFree(key); + } cur = cur->next; } return; @@ -28,7 +31,6 @@ parseDoc(char *docname) { if (doc == NULL ) { fprintf(stderr,"Document not parsed successfully. \n"); - xmlFreeDoc(doc); return; } diff --git a/doc/tutorial/index.html b/doc/tutorial/index.html index 4ce60be7..03e8588d 100644 --- a/doc/tutorial/index.html +++ b/doc/tutorial/index.html @@ -1,5 +1,5 @@ -Libxml Tutorial

Libxml Tutorial

John Fleck

Revision History
Revision 1June 4,2002
Revision 2June 12, 2002
Revision 3Aug. 31, 2002
Revision 4Nov. 10, 2002

Abstract

Libxml is a freely licensed C language library for handling +Libxml Tutorial

Libxml Tutorial

John Fleck

Revision History
Revision 1June 4, 2002
Revision 2June 12, 2002
Revision 3Aug. 31, 2002
Revision 4Nov. 10, 2002
Revision 5Dec. 15, 2002

Abstract

Libxml is a freely licensed C language library for handling XML, portable across a large number of platforms. This tutorial provides examples of its basic functions.

Introduction

Libxml is a C language library implementing functions for reading, creating and manipulating XML data. This tutorial diff --git a/doc/tutorial/xmltutorial.pdf b/doc/tutorial/xmltutorial.pdf index 31c293af..5a1a0f71 100644 Binary files a/doc/tutorial/xmltutorial.pdf and b/doc/tutorial/xmltutorial.pdf differ diff --git a/doc/tutorial/xmltutorial.xml b/doc/tutorial/xmltutorial.xml index 7469ed5b..14dc2ca6 100644 --- a/doc/tutorial/xmltutorial.xml +++ b/doc/tutorial/xmltutorial.xml @@ -37,6 +37,10 @@ 4 Nov. 10, 2002 + + 5 + Dec. 15, 2002 + @@ -381,14 +385,17 @@ parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) { void getReference (xmlDocPtr doc, xmlNodePtr cur) { + xmlChar *uri; cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) { - printf("uri: %s\n", xmlGetProp(cur, "uri")); - } + uri = xmlGetProp(cur, "uri"); + printf("uri: %s\n", uri); + xmlFree(uri); + } cur = cur->next; } - return; + return; } @@ -555,6 +562,7 @@ getReference (xmlDocPtr doc, xmlNodePtr cur) { Marcus Labib Iskander Christopher R. Harris Igor Zlatkovic + Niraj Tolia