????? ????? ???? ?? ?????? ???? ???? ?? ??? XML ?? Visual C# .NET

?????? ????????? ?????? ?????????
???? ???????: 316063 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ????? ??????? ???? ???? ?? ??? ????? ??? ????? ??????? (XML) ???????? Visual C# .NET.

??? ?????

XML predefines ????? ?????? ?????? ??????? ?????? ??? ???? ???? ???? ??? ????? ???? ?? ??? ?????:

Character Name Entity Reference Character Reference Numeric Reference
Ampersand & & &
Left angle bracket &lt; < &#38;#60;
Right angle bracket &gt; > &#62;
Straight quotation mark &quot; " &#39;
Apostrophe &apos; ' &#34;


???? ??????? ?????? ?????? ??? ?????? ??? ?????? ?????? ? ????? ???? ?????? ????. ????? ????? ??????? ????? ????? ?????. ??? ????? ????? ????? ??????? ????? ??? ?????? ??? ?????? ?????. ???????? ??? ???? ??? ??? ??????? ?? ????? ????? ????? ??? ???? ?????? ??????, ????? ??????? ????? ????? ?????

?? ???? ??????? ??? ??????? ????? ???????:
  • <
  • &
??? ?? ???? ?????? ??? ?? ??????? ???????? ?????? ?? ???? ?????? ?? ???? ??? ??? ????? ????? (??? ?????? ?????? ?? ????? ????) ???? ??? escaped. ??? escaping ?????? ????? ?? ??? ??? ??????? ???? ????? ????? ????? ????? ??? ???????.

?? ???? ??????? ?? ?? ??????? ??????? ???????:
  • >
  • '
  • "
??? ?? ???? ?????? ??? ?? ??????? ???????? ?????? ?? ???? ?????? ?? ??? ???? ??? escaped.

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

??? ?????: ??? XML ???? ??? ??????? ???????? ?? ????? ??????

??? ??????? Microsoft .NET Framework ??? ??????? ???????? ???? ??????? ?? ???? DataSet. ??? ????? ???????? ?? DataSet ??? ??? XML ???????? ????? WriteXml, ??? ??????? ?????? ?????? ???? ???? ????? ?? ????? "??????" ????? ????? ?????. ????? ??? ????? ????? XML ? ??? ??? ?????? DataSet ?? ????? ??????? ??? ?????.

????????: ??? XML ????? ??? ?????? XML ???? ?????? ?? ???? ????

?? ??? ??????? ??? XML ?? ?????? XML ???? ???? ?? ??? ?????? ?? ?????? ??? ?????? ??????. ?? ??? ?????????? ???????? ?????? ????? ??? ????? ?? ???? XmlDocument ?? ???? XmlReader.

???? ????? ????? ??????? ??? ?????? ??? ????? ????:
??? ??? ????? ????? entity_name ????? # ? ?? #.
??? ????? # ???? ???? # ?????? ?????? ??? ???.

???? ????? ????? ??????? ??? ?????? ??? ?????? ??????:
' < ' ?? ???? ????? ????? ???? ?? ?????? ???????? ??????? 0x3C, ?? ???. ???#, position #.
?? ????? ????? ??? ????? # ? # ?? ???? ??? ?????? ??? ???? ??? ?????? ?????? ???? ??? ???? ??? ?????? ?????? ?????? ??????.

??? ??? ??? XML ????? ??? ??? ?????? ?????? (&gt;) ?? ????? ?????? ?????? ('') ?????? ?????? ?????? (')XmlReader ????????? XmlDocument ?????? ??? ???????? ??? ??? ?????? ????? ??????? ??? ???? ???.

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

???????? ???? ???? "?" ??? ??? ?????? ??????:
  1. ????? ??? XML.
  2. ????? ????? Visual C# .NET ?? ?? ?????? ????????? ????????.

????? ??? XML

??? ? ??? ????????? ???????? ??????? ?? ??????? ?? ?? ???? ????? ?? Customers.xml:
<?xml version="1.0" standalone="yes"?>
<Customers>
<Customer>
<CustomerID>BLAUS</CustomerID>
<CompanyName>Blauer See Delikatessen</CompanyName>
<ContactName>Hanna Moos</ContactName>
<Region>test<ing</Region>
</Customer>
<Customer>
<CustomerID>SPLIR</CustomerID>
<CompanyName>Split Rail Beer & Ale</CompanyName>
<ContactName>Art raunschweiger</ContactName>
<Region>WY</Region>
</Customer>
</Customers>
				

????? ????? Visual C# .NET

  1. ????? ????? Windows Visual C# ?? .NET ???? ??? ???:
    1. ??? ????? Microsoft Visual Studio .NET.
    2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
    3. ?? ???? ?????? ????? ???? ? ???? ??? Visual C# ?????? ??? ????? Project ?? ???? ??? ????? Windows ??? ?????.
  2. ???? ???? ???? ???? ?? ????? ???? ?? ??????? DataGrid ?? ???? ??????? ??? ??????? ????????? Form1.cs.
  3. ????? ??????? ????????? ?? ??? True.
  4. ??????? ?????? ??????? ???????:
    using System.Xml;
    using System.IO;
    using System.Data.SqlClient;
    					
  5. ?? ?????? ????????? ???????? ??????? ??? ?????? ???????:
    string filepath = "C:\\Customers.xml";
    private void ReplaceSpecialChars(long linenumber)
            {
                System.IO.StreamReader strm;
                string strline;
                string strreplace = " ";
                string tempfile = "C:\\Temp.xml";
                try
                {
                    System.IO.File.Copy(filepath,tempfile,true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
    
                StreamWriter strmwriter = new StreamWriter(filepath);
                strmwriter.AutoFlush = true;
                strm = new StreamReader(tempfile);
                long i  = 0;
                while (i < linenumber - 1)
                {
                    strline = strm.ReadLine();
                    strmwriter.WriteLine(strline);
                    i = i + 1;
                }
    
                strline = strm.ReadLine();
                Int32 lineposition;
    		
                lineposition = strline.IndexOf("&");
                if (lineposition > 0) 
                {
                    strreplace = "&amp;";
                }
                else
                {
                    lineposition = strline.IndexOf("<",1);
                    if (lineposition > 0 )
                    {
                        strreplace = "<";
                    }
    
                }
                strline = strline.Substring(0, lineposition - 1) + strreplace + strline.Substring(lineposition + 1);
                strmwriter.WriteLine(strline);
    
                strline = strm.ReadToEnd();
                strmwriter.WriteLine(strline);
    
                strm.Close();
                strm = null;
    
                strmwriter.Flush();
                strmwriter.Close();
                strmwriter = null;
    
            }
    		
            public XmlDocument LoadXMLDoc() 
            {
            XmlDocument xdoc;
            long lnum;
    		
            try
            {
                xdoc = new XmlDocument();
                xdoc.Load(filepath);
            }
            catch (XmlException ex)
            {
                MessageBox.Show(ex.Message);
                lnum = ex.LineNumber;
                ReplaceSpecialChars(lnum);
    
                xdoc = LoadXMLDoc();
            }
        return (xdoc);
        }
    					
  6. ?? ?????? ????????? ???????? ??????? ??? ????? Button1_Click:
    XmlDocument xmldoc = new XmlDocument();
            xmldoc = LoadXMLDoc();
            XmlNode nextnode; 
            nextnode = xmldoc.FirstChild.NextSibling;
            this.textBox1.Text = nextnode.OuterXml.ToString();
    					
  7. ?? ?????? ????????? ???????? ??????? ??? ????? Button2_Click:
    DataSet ds = new DataSet();
                XmlDocument xdoc = new XmlDocument();
                SqlConnection cnNwind = new SqlConnection("Data source=myServerName;user id=myUser;Password=myPassword;Initial catalog=Northwind;");
                SqlDataAdapter daCustomers = new SqlDataAdapter("Select customerid,companyname,contactname, region from customers where region='WY'", cnNwind);
                string filepath = "C:\\Customers.xml";
                try
                {
                    daCustomers.Fill(ds, "Customers");
                    this.dataGrid1.DataSource = ds.Tables["Customers"];
                    ds.WriteXml(filepath);
                    xdoc.Load(filepath);
                    XmlNode nextnode; 
                    nextnode = xdoc.FirstChild.NextSibling;
                    textBox1.Text = nextnode.OuterXml.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
    					
  8. ????? ??????? ?? ????? ??????? SqlConnection ??? ??????? ?????? ?????? ??.
  9. ?????? ??????? ???????.
  10. ???? ??? Button1.

    ???? ??????? ?? ??? ??????? ???? ???? ????? ?? ??????? ???? ???? Required: An XML file with special characters ??????. ???? ?????? XML ?? ???? ??; ??? ??????? ?????
  11. ???? ??? Button2.

    ?? DataGrid ???? ??? companyname ?? ????? ??? ?????? XML ?? ??? ???? ??

?????

?????? ??? ??????? ??????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
251354????? ????? ???? ?? ?????? ???? ???? ?? ????? XML ?? Visual Basic

???????

???? ???????: 316063 - ????? ??? ??????: 10/???? ?????/1428 - ??????: 4.4
????? ???
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1
????? ??????: 
kbmt kbgrpdsmsxml kbhowtomaster kbmsxml KB316063 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????316063

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

 

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