XML檔案見下:
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" makevoucherruleid="">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly">
<s:AttributeType name="ivouchstate" rs:number="1">
<s:datatype dt:type="string" dt:maxLength="15" rs:maybenull="false"/>
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ivouchstate="Opening" csysbarcode="||SA17|0000000001" ufts="500" />
</rs:data>
</xml>
請問用VB怎么讀出csysbarcode的值?小弟是新手求原始碼哈
uj5u.com熱心網友回復:
這好象是記錄集物件保存的XML檔案。參考Microsoft XML 6.0,用XML物件來讀取。
uj5u.com熱心網友回復:
Dim strLine As String, n As Long, i As Long, blnFound As Boolean, strResult As String
Open "C:\\test\xml\1.xml" For Input As #1
Do Until EOF(1)
Line Input #1, strLine
n = InStr(strLine, "csysbarcode")
If n > 0 Then
For i = n + 1 To Len(strLine)
If blnFound Then
If Mid(strLine, i, 1) <> """" Then
strResult = strResult & Mid(strLine, i, 1)
Else
Exit Do
End If
End If
If Mid(strLine, i, 1) = """" And Not blnFound Then blnFound = True
Next i
End If
Loop
Close #1
MsgBox strResult
uj5u.com熱心網友回復:
在vb里表單上放一個list控制元件代碼如下:
Option Explicit
Dim XMLDoc As DOMDocument
Dim xList As IXMLDOMNodeList
Private Sub Form_Load()
Set XMLDoc = New DOMDocument
Dim n As Long
Dim i As Long
If XMLDoc.Load("\2.xml") Then
Set xList = XMLDoc.getElementsByTagName("test")
For i = 0 To xList.length - 1
Me.List1.AddItem xList.Item(i).Text
Next i
For n = 0 To xList.length - 1
For i = 0 To xList.Item(n).childNodes.length - 1
Me.List1.AddItem xList.Item(n).childNodes.Item(i).Text
Next i
Next n
End If
End Sub
uj5u.com熱心網友回復:
Sub test()
With CreateObject("Microsoft.XMLDOM")
.Load ("C:\Documents and Settings\Administrator\桌面\1.xml")
MsgBox .getElementsByTagName("xml").Item(0).ChildNodes.Item(1).ChildNodes(0).Attributes.getNamedItem("csysbarcode").Text
End With
End Sub
uj5u.com熱心網友回復:
Sub test1()
With CreateObject("Microsoft.XMLDOM")
.Load ("C:\Documents and Settings\Administrator\桌面\1.xml")
Set r = .DocumentElement.SelectSingleNode("//z:row")
Debug.Print r.Attributes(1).Value
Debug.Print r.Attributes(1).Text
Debug.Print r.getAttributeNode("csysbarcode").NodeValue
Debug.Print r.Attributes(1).NodeValue
End With
End Sub
uj5u.com熱心網友回復:
頂樓上!
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/89606.html
標籤:VB基礎類
上一篇:關于MDI視窗托盤的問題
