("Bookstore. XML "); // ================================================ ========= the result is: 2. Modify the node: Change the genre value of the node whose genre attribute value is "Li zenhong" to "Update Li zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore Node
Foreach (xmlnode Xn in nodelist) // traverses all subnodes
{
Xmlelement Xe
the node whose genre attribute value is "Li zenhong" to "Update Li zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre")
"update Li zenhong ", modify the text of the child node XmlNodeList nodeList = xmlDoc. SelectSingleNode ("bookstore"). ChildNodes; // obtain all the subnodes of the bookstore Node
Foreach (XmlNode xn in nodeList) // traverses all subnodes
{
XmlElement xe = (XmlElement) xn; // converts the subnode type to the XmlElement type
If (xe. GetAttribute ("genre") = "") // if the genre attribute value is ""
{
", modify the text of the child node
Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = "") // If the genre attribute value is ""{
property value "Li Zhanhong" to "Update Li Zhanhong" and modify the text of the node's child nodes to "Asian wins."
Copy Code code as follows:
XmlNodeList Nodelist=xmldoc.selectsinglenode ("bookstore"). childnodes;//gets all the child nodes of the bookstore node
foreach (XmlNode xn in nodelist)//traverse all child nodes
{
XmlElement xe= (XmlElement) xn;//Converts a child node type to a XmlElement type
if (
("bookstore"). childnodes;//gets all the child nodes of the bookstore node
foreach (XmlNode xn in nodelist)//traverse all child nodes
{
XmlElement xe= (XmlElement) xn;//Converts a child node type to a XmlElement type
if (XE. GetAttribute ("genre") = = "Li Zhanhong")//If genre property value is "Li Zhanhong"
{
Xe. SetAttribute ("Genre", "Update Li Zhanhong");//Mo
Zhanhong", the node's child node
XmlNodeList Nodelist=xmldoc.selectsinglenode ("bookstore"). childnodes;//gets all the child nodes of the bookstore node
foreach (XmlNode xn in nodelist)//traverse all child nodes
{
XmlElement xe= (XmlElement) xn;//Converts a child node type to a XmlElement type
if (XE. GetAttribute ("genre") = = "Li Zhanhong")//If genre property value is "Li Zhanhong"
{
child nodes of the bookstore nodeforeach (XmlNode xn in nodelist)//traverse all child nodes{XmlElement xe= (XmlElement) xn;//Converts a child node type to a XmlElement typeif (XE. GetAttribute ("genre") = = "Li Zhanhong")//If genre property value is "Li Zhanhong"{Xe. SetAttribute ("Genre", "Update Li Zhanhong");//Modify this property to "Update Li Zhanhong"XmlNo
Li zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = "") // If the genre attribute value is ""{
", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = "") // If the genre attribute value is ""{
. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = "") // If the genre attribute value is ""{Xe. setattribute ("genre", "Update lizan red"); // yo
the child node
Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = "") // If the genre attribute value is ""{Xe. set
"Update Li zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore Node
Foreach (xmlnode Xn in nodelist) // traverses all subnodes
{
Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement type
If (Xe. getattribute ("genre") = "") // If the genre attribute value is ""
{
is "Li zenhong" to "Update Li zenhong ", modify the text of the child node
Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = "") // If the genre attribute valu
zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore Node
Foreach (xmlnode Xn in nodelist) // traverses all subnodes
{
Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement type
If (Xe. getattribute ("genre") = "") // If the genre attribute value is ""
{
. Save ("bookstore. xml ");
2. Modify the node: Change the genre value of the node whose genre attribute value is "Li zenhong" to "update Li zenhong ", modify the text of the child node
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->XmlNodeList nodeList = xmlDoc. SelectSingleNode ("bookstore"). ChildNodes; // obtain all the subnodes of the bookstore Node
Foreach (XmlNode xn in nodeList) // traverses all subnodes
{
XmlElement
genre attribute value is "lizan red" to "Update lizan red", and change the text of the child node of the node to "Yasheng ".
Copy code The Code is as follows: xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore Node
Foreach (xmlnode Xn in nodelist) // traverses all subnodes
{
Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement type
If (
); // Add it to the Xmlelement xesub2 = xmldoc. createelement ("author ");Xesub2.innertext = "Hou Jie ";Xe1.appendchild (xesub2 );Xmlelement xesub3 = xmldoc. createelement ("price ");Xesub3.innertext = "58.3 ";Xe1.appendchild (xesub3 );Root. appendchild (xe1); // Add it to the Xmldoc. Save ("Bookstore. xml ");// ================================================ ==========Result:2. Modify the node: Change the genre value of the node whose genre attribute value is "Li zenhong" to "Update Li zenhong
. Modify the node: Change the genre value of the node whose genre attribute value is "Li zenhong" to "Update Li zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore Node
Foreach (xmlnode Xn in nodelist) // traverses all subnodes
{
Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement type
If (
node whose genre attribute value is "Li zenhong" to "Update Li zenhong ", modify the text of the child node Xmlnodelist nodelist = xmldoc. selectsinglenode ("Bookstore"). childnodes; // obtain all the subnodes of the bookstore NodeForeach (xmlnode Xn in nodelist) // traverses all subnodes{Xmlelement Xe = (xmlelement) xn; // converts the subnode type to the xmlelement typeIf (Xe. getattribute ("genre") = ""
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.