zoukankan      html  css  js  c++  java
  • 初步学习XML的基本代码

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.Xml;
     7 
     8 namespace Day08_XML
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14             XmlDocument doc = new XmlDocument();
    15             doc.Load("Computer.xml");
    16            XmlNode root=doc.DocumentElement;
    17             foreach(XmlNode item in root.ChildNodes){
    18                 string id = item.Attributes["id"].Value;
    19                
    20            
    21                 Console.WriteLine(id);
    22                 Console.WriteLine("名称为"+item["Name"].InnerText);
    23             
    24             
    25             }
    26 
    27            //foreach(XmlNode item in root.ChildNodes){
    28 
    29                         //item是XML中的Computer对象
    30            //     foreach(XmlNode child in item.ChildNodes){
    31 
    32            //         switch(child.Name){
    33                     
    34            //             case "Name":
    35            //                 Console.WriteLine("我的电脑是:"+child.InnerText);
    36            //                 break;
    37                     
    38                     
    39                     
    40            //         }
    41                  
    42             
    43            // }
    44          
    45 
    46            // }
    47             Console.ReadLine();
    48         }
    49     }
    50 }
    1 <?xml version="1.0" encoding="utf-8" ?> 
    2 <Computer>
    3   <Computers id="110">
    4   <Name>联想</Name>
    5    </Computers>
    6   <Computers id="120">
    7     <Name>苹果</Name>
    8   </Computers>
    9 </Computer>
  • 相关阅读:
    php主要输出方式的区别
    文件操作
    会话
    Jquery常用函数及功能
    AJAX
    php 审核注册
    转载图片上传预览 代码
    php笔记-图片上传
    php 练习题-session与 cookie的 取值赋值
    php学习笔记-会话控制简单介绍session和cookie(一)
  • 原文地址:https://www.cnblogs.com/ruyan886621/p/6590330.html
Copyright © 2011-2022 走看看