From d09ab089457ae3c20cc98f9afa03379c6ebf9598 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 25 Mar 2004 06:59:32 +0000 Subject: [svn-inject] Installing original source version --- doc/tutorial/ar01s07.html | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doc/tutorial/ar01s07.html (limited to 'doc/tutorial/ar01s07.html') diff --git a/doc/tutorial/ar01s07.html b/doc/tutorial/ar01s07.html new file mode 100644 index 0000000..395b780 --- /dev/null +++ b/doc/tutorial/ar01s07.html @@ -0,0 +1,30 @@ +Writing Attribute

Writing Attribute

+Writing an attribute is similar to writing text to a new element. In + this case, we'll add a reference URI to our + document. Full code:Appendix F, Code for Add Attribute Example.

+ A reference is a child of the story + element, so finding the place to put our new element and attribute is + simple. As soon as we do the error-checking test in our + parseDoc, we are in the right spot to add our + element. But before we do that, we need to make a declaration using a + data type we have not seen yet: +

+	xmlAttrPtr newattr;
+      

+ We also need an extra xmlNodePtr: +

+	xmlNodePtr newnode;
+      

+

+ The rest of parseDoc is the same as before until we + check to see if our root element is story. If it is, + then we know we are at the right spot to add our element: + +

+	1 newnode = xmlNewTextChild (cur, NULL, "reference", NULL);
+	2 newattr = xmlNewProp (newnode, "uri", uri);	
+      

+

1

First we add a new node at the location of the current node + pointer, cur. using the xmlNewTextChild function.

+

Once the node is added, the file is written to disk just as in the + previous example in which we added an element with text content.

-- cgit v1.2.3