TO HOW: ???? ?? Visual Basic .NET ?? ??? ??? XML ???? ??? ????? ???? ?????

???? ?????? ???? ??????
???? ID: 308060 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ???? ????? ???? ?? ?? Visual Basic .NET ?? ????? ?? ???? ??????????? ??????? ???? (XML) ???? ??? ????? ???? ?? ???????????? ???? ?? ??? ???? ?????

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

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;


????? ??? ??????, ampersand ?? ???? ??????? escape ???? ?? ??? ?? ???? ?? ???? ?? ?????? ?? ????? ?? ????? ?? ?? ???????? ???? ?? ?????? ?? ????? ?? ???? ???; ?? ????? ?? ?? ?????? ?? ??? ?? ?? ??? ???? ???? ????, ???????? ???? ?? ?????? ?? ????? ?? ???? ??? ???? ??????? ?? ?? ???

??? ?? ?? ?? ????? ?? ????? declaring ???
  • lt
  • amp
?????? ????? ????? ??????????? ??? ?? ?????? ???? (????? ??? ?????? ?? ampersand) escaped ???? ?? ??? ?? ?? ???? ?? ??? ???? ?? ?????? ?? ??? ??? ????? ???? ?? ??? ???? ??? ??; ????? escaping ?? ?? ????? ?? ??? ?????? ?? ?? ?????? ?? ?????? ??? ??? ??? ?????? ?????? ?????? ???

??? ?? ????? ??? ????? ?? ???? ?? declaring ???
  • gt
  • apos
  • quot
???? ?????? ?? ??? ??? ?????? ????? ????? ??????????? ??? ?? ?? ????? ???? ?? ??? ???? ?? ??? escaped ?????

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

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

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

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

???-??? XML ???? ??? ?? ???? ????? ???? ?? ??? XML ???? ?? ???? ?? ?? ????? ?????? ?? ????? ????; ?? ???????? ???, ???? ????? ????????? ??? ??? ??? ???? ??? ???XmlDocument???????? ?? ????XmlReader???????? ???

????? ?????? ??????? ?? ?? ?? ampersand ???? ??? ??:
????? ???? ??? ??? ?????? ??entity_name??????:#, ??????#.
???? ????#?? ??????#????? ???? ?? ??? ?????? ?? ???????????? ???

????? ?????? ???? ?? ?? ???? ????? ??? ?????? ??? ?? ??:
'<' character,="" hexadecimal="" value="" 0x3c,cannot="" be="" included="" in="" a="" name.="" line=""></'>#, ??????#.
?? ?????? ?????, ?????? ???#?? ??????#????? ??? ?????? ???? ????? ??, ????? ????? ????? ??? ?????? ???? ??? ?? ?????? ????? ???? ?????

XML ???? ??? ???? ??? ?????? (>), ?? ???? ?????? ????? (") ?? ??? apostrophe ('), ??? ?? ?? ??????? ???XmlReader??XmlDocument???? ?? ???? ??????????? ?? ?????? ?? ??? ?????? ?? ??????? ???????? ???

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

Ampersand ?? ????? ??? ?????? ' ???? ????? ??:
  1. XML ???? ??????
  2. Visual Basic .NET ????????? ?????, ?? ???? ??? ??? ???????? ?????

XML ????? ?????

?? ????????? ????? ?? ????? ??? ?? Notepad ??? ???????, ?? ?? ???? ?? ??? ??? ??????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 Basic .NET ????????? ?????

  1. ??? ??? Visual Basic .NET Windows ????? ??????????
  2. ?? ???? ?? ??? ??? ?????-????-????? ???????? ?? ????? ??????? ??????????????????, ?? ??DataGrid.
  3. ??? ????Multiline?? ?????? ????????? ?? ???True.
  4. ????? ???????? ???? ????:
    Imports System.Xml
    Imports System.IO
    Imports System.Data.SqlClient
    					
  5. ????? ??? ?? ???
    Inherits System.Windows.Forms.Form
    ?? ????????? ?????, ?? ????? ??? ????? ?? ???????:
     Dim filepath As String = "C:\customers.xml"
    Private Sub ReplaceSpecialChars(ByVal linenumber As Long)
            Dim strm As StreamReader
            Dim strline As String
            Dim strreplace As String
    
            Dim tempfile As String = "C:\temp.xml"
            Try
                FileCopy(filepath, tempfile)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
            Dim strmwriter As New StreamWriter(filepath)
            strmwriter.AutoFlush = True
    
            strm = New StreamReader(tempfile)
    
    
            Dim i As Long = 0
            While i < linenumber - 1
                strline = strm.ReadLine
                strmwriter.WriteLine(strline)
                i = i + 1
            End While
    
            strline = strm.ReadLine
            Dim lineposition As Int32
            lineposition = InStr(strline, "&")
            If lineposition > 0 Then
                strreplace = "&amp;"
            Else
                lineposition = InStr(2, strline, "<")
                If lineposition > 0 Then
                    strreplace = "<"
                End If
            End If
            strline = Mid(strline, 1, lineposition - 1) + strreplace + Mid(strline, lineposition + 1)
            strmwriter.WriteLine(strline)
    
            strline = strm.ReadToEnd
            strmwriter.WriteLine(strline)
    
            strm.Close()
            strm = Nothing
    
            strmwriter.Flush()
            strmwriter.Close()
            strmwriter = Nothing
    
        End Sub
    
        Public Function LoadXMLDoc() As XmlDocument
            Dim xdoc As XmlDocument
            Dim lnum As Long
            Dim pos As Long
            Dim Newxml As String
            Try
                xdoc = New XmlDocument()
                xdoc.Load(filepath)
            Catch ex As XmlException
                MessageBox.Show(ex.Message)
                lnum = ex.LineNumber
                ReplaceSpecialChars(lnum)
    
                xdoc = LoadXMLDoc()
    
            End Try
            Return (xdoc)
        End Function
    					
  6. ?? ????????? ????? ?? ??? ????? ??? ???????????? ????,?? ?????Button1:
    Dim xmldoc As New XmlDocument()
            xmldoc = LoadXMLDoc()
            Dim nextnode As XmlNode
            nextnode = xmldoc.FirstChild.NextSibling
            TextBox1.Text = nextnode.OuterXml
    					
  7. ?? ????????? ????? ?? ??? ????? ??? ???????????? ????,?? ?????Button2:
    Dim ds As New DataSet()
            Dim xdoc As New XmlDocument()
            Dim cnNwind As New SqlConnection("Data source=myservername;user id=myuser;Password=mypassword;Initial catalog=Northwind;")
            Dim daCustomers As New SqlDataAdapter("Select customerid,companyname,contactname, region from customers where region='WY'", cnNwind)
            Dim filepath As String
            Try
                daCustomers.Fill(ds, "Customers")
                DataGrid1.DataSource = ds.Tables(0)
                ds.WriteXml("C:\Dataset.xml")
                xdoc.Load("C:\Dataset.xml")
                Dim nextnode As XmlNode
                nextnode = xdoc.FirstChild.NextSibling
                TextBox1.Text = nextnode.OuterXml.ToString
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    					
  8. ????? ???, ?????????? ???, ?? Microsoft SQL ????? ?? ??? ?? ?? ???? ????? ?? ?????? ???? ?? ??? ??????? ????????? ?????
  9. ????????? ?????, ?? ???? ??? ??? ??????
  10. ????? ????,Button1.

    ???? ????????? "??????: ??? XML ???? ?? ??? ????? ????" ??? ??? explained ????????? ?? ????? ?? ??? ???? ???? XML ???? ??? ?? ????????? ???? ????? ?????; ampersand ?? ???? ??? ??
  11. Button2 ????? ?????

    ?????DataGrid,companyname??? ampersand ?? ????? ?????XML ???? ?? ??? ?????? ??

??????

???????? ??????? ?? ???, ???? ?? ???? ?????? ?? ????? ?? ???? ?? Microsoft ???????? ??? ?????::
251354TO HOW: ???? ?? Visual Basic ?? ????????? ??? ??? XML ????? ???? ?????

???

???? ID: 308060 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
??????: 
kbgrpdsmsxml kbhowtomaster kbmsxml kbmt KB308060 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:308060

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

 

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