???? ???? ?? ??? ??????? ?? XML ??? XmlDocument ???? ?? ??? ?????????? ????? SDK

???? ?????? ???? ??????
???? ID: 301233 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
?? ???? ????? ???? ?? ??? ???????? ???? ?????? ????? ???? ????????? ????????:
  • System.XML
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ????? ?? ?????? ????, ?? XML ?? ??? ?????? ???? ?? ??? ???? ?????? ?? XmlDocument ?????

??????????

????? ???? ???????? ?????????, ?????????? outlines, ??????? ???? ??????, ?? ???? ??? ?? ?? ?? ???????? ????:
  • Microsoft Windows 2000 Professional, Windows 2000 ?????, Windows 2000 ?????, ?? Windows NT 4.0 ????? ?????
  • Microsoft Visual Studio.???
?? ???? ????? ?? ?? ?? ?????????? ?? ??? ?????? ??? ????:
  • XML ????????
  • ????? ?? ???? XML ????? ?? ???
  • ????????? ???????? ???? (????? DOM)

XML ?????? ???? ?? ??? XmlDocument ???? ?? ????? ???? ?? ??? ????

  1. ??? ??? Visual Basic ?? C# ????? ??? ????????? ????? ????? ?????????????
  2. ????????? ???? ?? ????????? System.Xml ???????? ?? ???????? ?????
  3. Imports ??? Xml ???????? ?? ?? ????? ???? ???? ?? ??? ??? ???? ??? ??? XmlTextReader declarations ????? ???????? ???? ??? ??? ?? Imports ??? ?? ???? ???? ?? declarations ?? ??? ????? ???? ??????
    Visual Basic.??? ???
    Imports System.Xml
    C# ???
    using System.Xml;
    
  4. ?? XmlDocument ???? ?????, ?? ??? ??? ???? ?? ??? ??? ?????? ?? ????? ?????

    XmlDocument ???? XML ????????? ?? ???????????? ???? ??, ?? ????????? ?????, ??????, ?? XmlReader?? ??? ???? ?? ??? ?? ??? ?????? ???

    Visual Basic.??? ???
    Dim myXmlDocument as XmlDocument = new XmlDocument()
    myXmlDocument.Load ("books.xml")
    
    C# ???
    XmlDocument myXmlDocument = new XmlDocument();
    myXmlDocument.Load ("books.xml");
    
    ??? Books.xml ????? ???? ????? ???? ???? ??, ?????? ?? ??? ???? ??? ???? Books.xml ?????? ????? Books.xml ????? ?? ????? ?? ?? ??? Visual ???????????? ?????? ????? ?????????? ????? ??? (SDK)?
  5. XmlNode ???????? ??????? ?? ?? ??? ??????? ???? ?? ??? ??? ?????? ???? ??? ?? ????? XmlNode ???????? ???? XML ??? ????? ?? ??? DocumentElement ??? ?? XmlDocument ???? ???
    Visual Basic.??? ???
    Dim node as XmlNode
    node = myXmlDocument.DocumentElement
    
    C# ???
    XmlNode node;
    node = myXmlDocument.DocumentElement;
    
  6. ????????? ???? ?? ?????? ?? ?????? ?? iterate ?? ????? ??? "?????" ?????? ??? ???????? ?? ChildNodes ??? ?? ??? construct looping ?? ??? ???????? "?????" ????? ?? ?? ??? ??? ?? ??? ????? ?? ??? ????? ????? ????? ?? ????? ?????????
    Visual Basic.??? ???
    Dim node2 As XmlNode 'Used for internal loop.
    Dim nodePriceText As XmlNode
    For Each node In node.ChildNodes
       'Find the price child node.
       For Each node2 In node.ChildNodes
          If node2.Name = "price" Then
             '                    nodePriceText = node2.InnerText
             Dim price As Decimal
             price = System.Decimal.Parse(node2.InnerText)
    
             ' Double the price.
             Dim newprice As String
             newprice = CType(price * 2, Decimal).ToString("#.00")
             Console.WriteLine("Old Price = " & node2.InnerText & Strings.Chr(9) & "New price = " & newprice)
             node2.InnerText = newprice
          End If
       Next
    Next
    
    C# ???
    foreach(XmlNode node1 in node.ChildNodes)
       foreach (XmlNode node2 in node1.ChildNodes)
          if (node2.Name == "price")
             {
                Decimal price = Decimal.Parse(node2.InnerText);
                // Increase all the book prices by 20%
                String newprice = ((Decimal)price*(new Decimal(1.20))).ToString("#.00");
                Console.WriteLine("Old Price = " + node2.InnerText + "\tNew price = " + newprice);
                node2.InnerText = newprice;
              }
    
  7. ????????? XML ?? ???? ??? ?? ???? ?? ????? ??? ?????? ?? ??? ?????? ???? XmlDocument ???? ?? ?? ????? ???? InflatedPriceBooks.xml.

    ??? ?? XML ???? ???????, ??????? ?? XmlWriters?? ??? ?????? ?? ??? ?????? ???? ?? ????? ?? ???? ????
    Visual Basic.??? ???
    myXmlDocument.Save("InflatedPriceBooks.xml")
    
    C# ???
    myXmlDocument.Save("InflatedPriceBooks.xml");
    
  8. ????? ?? ???? ????????? ?? ??????

??????

???? ??????? ?? ???, ????? ??? ?????? ?? ????:
XML ???????:???? ????? XML ?????? ?? C# ???????? ??????, ???????? ???? Manipulation

????????? ???????? ???? (???) ???? 1

????????? ???????? ???? ???

XmlDocument ????

XmlNode ????

XML ????????? ???????? ???? (????? DOM)

???

???? ID: 301233 - ????? ???????: 12 ??? 2012 - ??????: 9.0
???? ???? ???? ??:
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
??????: 
kbhowtomaster kbmt KB301233 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:301233

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com