如何在VB.NET中获取XML的读写代码? [英] How to I acquire read-write codes for XML in VB.NET?
本文介绍了如何在VB.NET中获取XML的读写代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在VB.NET中获取XML的读写代码?
所以我想在VB.NET中读写XML函数。
像这样:
[ ^ ]
但我想添加每个使用命令。
(所以:XML.Text = XML.Text + [文字])
我有什么试过:
我想要这个代码用于XML:
How to I acquire read-write codes for XML in VB.NET?
So I want to read-write XML functions in VB.NET.
Like this:
[^]
But I want to adding for each using command.
(So: XML.Text = XML.Text + [Text])
What I have tried:
I want to like this codes for XML:
Public Class ini
' API functions
Private Declare Ansi Function GetPrivateProfileString _
Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String,
ByVal lpKeyName As String, ByVal lpDefault As String,
ByVal lpReturnedString As System.Text.StringBuilder,
ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
Private Declare Ansi Function WritePrivateProfileString _
Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String,
ByVal lpKeyName As String, ByVal lpString As String,
ByVal lpFileName As String) As Integer
Private Declare Ansi Function GetPrivateProfileInt _
Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
(ByVal lpApplicationName As String,
ByVal lpKeyName As String, ByVal nDefault As Integer,
ByVal lpFileName As String) As Integer
Private Declare Ansi Function FlushPrivateProfileString _
Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As Integer,
ByVal lpKeyName As Integer, ByVal lpString As Integer,
ByVal lpFileName As String) As Integer
Dim strFilename As String
' Constructor, accepting a filename
Public Sub New(ByVal Filename As String)
strFilename = Filename
End Sub
' Read-only filename property
ReadOnly Property FileName() As String
Get
Return strFilename
End Get
End Property
Public Function GetString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String) As String
' Returns a string from your INI file
Dim intCharCount As Integer
Dim objResult As New System.Text.StringBuilder(256)
intCharCount = GetPrivateProfileString(Section, Key, [Default], objResult, objResult.Capacity, strFilename)
If intCharCount > 0 Then GetString = Left(objResult.ToString, intCharCount)
End Function
Public Function GetInteger(ByVal Section As String, ByVal Key As String, ByVal [Default] As Integer) As Integer
' Returns an integer from your INI file
Return GetPrivateProfileInt(Section, Key, [Default], strFilename)
End Function
Public Function GetBoolean(ByVal Section As String, ByVal Key As String, ByVal [Default] As Boolean) As Boolean
' Returns a boolean from your INI file
Return (GetPrivateProfileInt(Section, Key, CInt([Default]), strFilename) = 1)
End Function
Public Sub WriteString(ByVal Section As String, ByVal Key As String, ByVal Value As String)
' Writes a string to your INI file
WritePrivateProfileString(Section, Key, Value, strFilename)
Flush()
End Sub
Public Sub WriteInteger(ByVal Section As String, ByVal Key As String, ByVal Value As Integer)
' Writes an integer to your INI file
WriteString(Section, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteBoolean(ByVal Section As String, ByVal Key As String, ByVal Value As Boolean)
' Writes a boolean to your INI file
WriteString(Section, Key, CStr(CInt(Value)))
Flush()
End Sub
Private Sub Flush()
' Stores all the cached changes to your INI file
FlushPrivateProfileString(0, 0, 0, strFilename)
End Sub
End Class
推荐答案
你没有。您发布的代码适用于.INI文件。用于读取/写入XML文件的等效代码已经在.NET Framework中。您编写的代码将使用这些类来针对您的特定应用程序读取XML模式。
有多种不同的方式来读/写/导航/解析XML文件。您使用哪种方法取决于您的应用程序要求。
You don't. The code you posted is for .INI files. The equivilent code for reading/writing XML files is already in the .NET Framework. The code you write will use those classes to read write against your XML schema for your particular application.
There's a variety of different ways to read/write/navigate/parse XML files. Which method you use depends on your application requirements.
这篇关于如何在VB.NET中获取XML的读写代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文