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 A number of people have generously offered feedback, code and
+ A number of people have generously offered feedback, code and
suggested improvements to this tutorial. In no particular order:
-
+
Check to see that the document was successfully parsed. If it
was not, libxml will at this point
register an error and stop.
- One common example of an error at this point is improper
+ 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.
Retrieve the document's root element. Check to make sure the document actually contains something. 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"))) {
-
@@ -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.
-
+
If you are using a DTD that declares a fixed or
default value for the attribute, this function will retrieve it.
-
+
Daniel Veillard Marcus Labib Iskander Christopher R. Harris Igor Zlatkovic Daniel Veillard Marcus Labib Iskander Christopher R. Harris Igor Zlatkovic Niraj Tolia
Note Note
printf("uri: %s\n", xmlGetProp(cur, "uri"));
- }
+
uri = xmlGetProp(cur, "uri");
+ printf("uri: %s\n", uri);
+ xmlFree(uri);
+ }
cur = cur->next;
}
- return;
+ return;
}
Note Note
![]() | Warning |
---|---|
A common mistake is to use different formats for the internal data + support every format anyone has ever heard of. WarningA 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 @@ -
Copyright © 2002 John Fleck
Revision History | |
---|---|
Revision 1 | June 4,2002 |
Revision 2 | June 12, 2002 |
Revision 3 | Aug. 31, 2002 |
Revision 4 | Nov. 10, 2002 |
Table of Contents
Abstract
Libxml is a freely licensed C language library for handling +
Copyright © 2002 John Fleck
Revision History | |
---|---|
Revision 1 | June 4, 2002 |
Revision 2 | June 12, 2002 |
Revision 3 | Aug. 31, 2002 |
Revision 4 | Nov. 10, 2002 |
Revision 5 | Dec. 15, 2002 |
Table of Contents
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.
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 @@