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/ar01s08.html | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libxml2-2.9.10/doc/tutorial/ar01s08.html (limited to 'libxml2-2.9.10/doc/tutorial/ar01s08.html') diff --git a/libxml2-2.9.10/doc/tutorial/ar01s08.html b/libxml2-2.9.10/doc/tutorial/ar01s08.html new file mode 100644 index 0000000..758f811 --- /dev/null +++ b/libxml2-2.9.10/doc/tutorial/ar01s08.html @@ -0,0 +1,38 @@ +Retrieving Attributes

Retrieving Attributes

+Retrieving the value of an attribute is similar to the previous + example in which we retrieved a node's text contents. In this case we'll + extract the value of the URI we added in the previous + section. Full code: Appendix G, Code for Retrieving Attribute Value Example.

+ The initial steps for this example are similar to the previous ones: parse + the doc, find the element you are interested in, then enter a function to + carry out the specific task required. In this case, we call + getReference: +

+void
+getReference (xmlDocPtr doc, xmlNodePtr cur) {
+
+	xmlChar *uri;
+	cur = cur->xmlChildrenNode;
+	while (cur != NULL) {
+	    if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) {
+		   1 uri = xmlGetProp(cur, "uri");
+		    printf("uri: %s\n", uri);
+		    xmlFree(uri);
+	    }
+	    cur = cur->next;
+	}
+	return;
+}
+      

+ +

1

+ The key function is xmlGetProp, which returns an + xmlChar containing the attribute's value. In this case, + we just print it out. +

[Note]Note

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

+

+ +

-- cgit v1.2.3