| Name | Size | Mode | Actions |
|---|---|---|---|
| images/ | - | 0755 | rm |
| apa.html | 2114 | 0644 | editdlrm |
| apb.html | 2026 | 0644 | editdlrm |
| apc.html | 3094 | 0644 | editdlrm |
| apd.html | 3232 | 0644 | editdlrm |
| ape.html | 3096 | 0644 | editdlrm |
| apf.html | 2949 | 0644 | editdlrm |
| apg.html | 3022 | 0644 | editdlrm |
| aph.html | 3600 | 0644 | editdlrm |
| api.html | 1899 | 0644 | editdlrm |
| ar01s02.html | 3298 | 0644 | editdlrm |
| ar01s03.html | 5718 | 0644 | editdlrm |
| ar01s04.html | 6223 | 0644 | editdlrm |
| ar01s05.html | 7422 | 0644 | editdlrm |
| ar01s06.html | 3849 | 0644 | editdlrm |
| ar01s07.html | 3866 | 0644 | editdlrm |
| ar01s08.html | 3894 | 0644 | editdlrm |
| ar01s09.html | 7603 | 0644 | editdlrm |
| includeaddattribute.c | 1136 | 0644 | editdlrm |
| includeaddkeyword.c | 1320 | 0644 | editdlrm |
| includeconvert.c | 1808 | 0644 | editdlrm |
| includegetattribute.c | 1171 | 0644 | editdlrm |
| includekeyword.c | 1351 | 0644 | editdlrm |
| includexpath.c | 1491 | 0644 | editdlrm |
| index.html | 5930 | 0644 | editdlrm |
| ix01.html | 2545 | 0644 | editdlrm |
| xmltutorial.pdf | 51709 | 0644 | editdlrm |
/usr/share/doc/libxml2-devel/tutorial/ar01s08.html (3894B)
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"))) {
uri = xmlGetProp(cur, "uri");
printf("uri: %s\n", uri);
xmlFree(uri);
}
cur = cur->next;
}
return;
}
| The key function is xmlGetProp, which returns an xmlChar containing the attribute's value. In this case, we just print it out.
| ||||