Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Tele marketing executive
nuwandse
Updated:
Today at 12:27 PM
Ad icon
Singapore V2ray VPN for Zoom Package Tunneling
hu KANNA
Updated:
Yesterday at 7:34 PM
Ad icon
Gampaha
Thenya Mishel
menuka2000
Updated:
Wednesday at 10:48 PM
Handmade Character Soft Toy Bluey Bingo
anil1961
Updated:
Aug 3, 2026
Colombo
Dahua POE Switch 8 Ports (DH-PFS3010-8ET-65)
hashaz2012
Updated:
Aug 3, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Open Forum
මොඩකමේ සීමාව පැනීම..
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="gosmart" data-source="post: 15029491" data-attributes="member: 314820"><p><span style="font-size: 22px"><span style="color: Red"><strong>Now that you’ve seen that you can move around in the XML document and even get the values of the</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>elements, let’s examine how to change the structure of the document by adding nodes to the books</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>document you’ve been using until now.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>To insert new elements in the list, you need to examine the new methods that are placed on the</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>XmlDocument and XmlNode classes, shown in Table 22-4. The XmlDocument class has methods that</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>enable you to create new XmlNode and XmlElement instances, which is nice because both of these</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>classes have only a protected constructor, which means you cannot create an instance of either directly</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>with new.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>The methods in Table 22-4 are all used to create the nodes themselves, but after calling any of them you</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>have to do something with them before they become interesting. Immediately after creation, the nodes</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>contain no additional information, and they are not yet inserted into the document. To do either, you</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>Using XML in Your Application ❘ 741</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>should use methods that are found on any class derived from XmlNode (including XmlDocument and</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>XmlElement), described in the following table:</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>METHOD DESCRIPTION</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>AppendChild Appends a child node to a node of type XmlNode or a derived type. Remember</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>that the node you append appears at the bottom of the list of children of the</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>node on which the method is called. If you don’t care about the order of the children,</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>there’s no problem; if you do care, remember to append the nodes in the</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>correct sequence.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>InsertAfter Controls exactly where you want to insert the new node. The method takes two</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>parameters — the first is the new node and the second is the node after which</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>the new node should be inserted.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>InsertBefore Works exactly like InsertAfter, except that the new node is inserted before</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>the node you supply as a reference.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>TABLE 22-4: Methods for Creating Nodes</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>METHOD DESCRIPTION</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>CreateNode Creates any kind of node. There are three overloads of the method, two of</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>which enable you to create nodes of the type found in the XmlNodeType</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>enumeration and one that enables you to specify the type of node to use as</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>a string. Unless you are quite sure about specifying a node type other than</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>those in the enumeration, use the two overloads that use the enumeration. The</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>method returns an instance of XmlNode that can then be cast to the appropriate</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>type explicitly.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>CreateElement A version of CreateNode that creates only nodes of the XmlDocument variety.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>CreateAttribute A version of CreateNode that creates only nodes of the XmlAttribute variety.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>CreateTextNode Creates — yes, you guessed it — nodes of the type XmlTextNode</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>CreateComment This method is included here to highlight the diversity of node types that can</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>be created. This method doesn’t create a node that is actually part of the data</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>represented by the XML document, but rather is a comment meant for any</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>human eyes that might have to read the data. You can pick up comments when</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>reading the document in your applications as well.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>In the Following Try It Out, you build on the previous example and insert a book node in the books.xml</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>document. There is no code in the example to clean up the document (yet), so if you run it several times</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>you will probably end up with a lot of identical nodes.</strong></span></span></p><p><span style="font-size: 22px"><span style="color: Red"><strong>742 ❘</strong></span></span></p></blockquote><p></p>
[QUOTE="gosmart, post: 15029491, member: 314820"] [SIZE="6"][COLOR="Red"][B]Now that you’ve seen that you can move around in the XML document and even get the values of the elements, let’s examine how to change the structure of the document by adding nodes to the books document you’ve been using until now. To insert new elements in the list, you need to examine the new methods that are placed on the XmlDocument and XmlNode classes, shown in Table 22-4. The XmlDocument class has methods that enable you to create new XmlNode and XmlElement instances, which is nice because both of these classes have only a protected constructor, which means you cannot create an instance of either directly with new. The methods in Table 22-4 are all used to create the nodes themselves, but after calling any of them you have to do something with them before they become interesting. Immediately after creation, the nodes contain no additional information, and they are not yet inserted into the document. To do either, you Using XML in Your Application ❘ 741 should use methods that are found on any class derived from XmlNode (including XmlDocument and XmlElement), described in the following table: METHOD DESCRIPTION AppendChild Appends a child node to a node of type XmlNode or a derived type. Remember that the node you append appears at the bottom of the list of children of the node on which the method is called. If you don’t care about the order of the children, there’s no problem; if you do care, remember to append the nodes in the correct sequence. InsertAfter Controls exactly where you want to insert the new node. The method takes two parameters — the first is the new node and the second is the node after which the new node should be inserted. InsertBefore Works exactly like InsertAfter, except that the new node is inserted before the node you supply as a reference. TABLE 22-4: Methods for Creating Nodes METHOD DESCRIPTION CreateNode Creates any kind of node. There are three overloads of the method, two of which enable you to create nodes of the type found in the XmlNodeType enumeration and one that enables you to specify the type of node to use as a string. Unless you are quite sure about specifying a node type other than those in the enumeration, use the two overloads that use the enumeration. The method returns an instance of XmlNode that can then be cast to the appropriate type explicitly. CreateElement A version of CreateNode that creates only nodes of the XmlDocument variety. CreateAttribute A version of CreateNode that creates only nodes of the XmlAttribute variety. CreateTextNode Creates — yes, you guessed it — nodes of the type XmlTextNode CreateComment This method is included here to highlight the diversity of node types that can be created. This method doesn’t create a node that is actually part of the data represented by the XML document, but rather is a comment meant for any human eyes that might have to read the data. You can pick up comments when reading the document in your applications as well. In the Following Try It Out, you build on the previous example and insert a book node in the books.xml document. There is no code in the example to clean up the document (yet), so if you run it several times you will probably end up with a lot of identical nodes. 742 ❘[/B][/COLOR][/SIZE] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom