从XML文件获取文本到字符串

时间:2016-03-09 14:08:17

标签: xml vba excel-vba excel

我有一个xml文件,我想从数字标签中取一个文本('aaa')到一个字符串。它看起来像这样:

<header_xml> <number>aaa</number> </header_xml>

我尝试使用互联网上找到的方法,但它们不起作用。

这是我的代码:

Set oXMLFile = CreateObject("Microsoft.XMLDOM")
sGeneratorPath = ThisWorkbook.Path

With Application.FileDialog(msoFileDialogOpen) ' --- Open FileDialog
    .InitialFileName = sGeneratorPath ' --- inital path
    .Filters.Clear
    .Filters.Add "XML Files (*.xml)", "*.xml" ' --- add filter to choose only xml files
    .AllowMultiSelect = False ' --- to select only one file

    If .Show = False Then ' --- if operation aborted, display message
        MsgBox "Operation Cancelled"
        End
    End If

    sXMLPath = .SelectedItems(1) ' --- path of xml file
End With

oXMLFile.Load (sXMLPath)

Set HWNode = oXMLFile.SelectSingleNode("/header_xml/number/")
sHWID = HWNode.Text
MsgBox sHWID

MsgBox "Done"

1 个答案:

答案 0 :(得分:2)

你真的很亲密。只需在 1. Create a slider 2.Show the "Identity Inspector" 3.Add a "User Defined Runtime Attribute" 4.Set the key path to "layer.transform.rotation.z", the type as "String" ("Number" won't allow floating point values) (possible since Xcode 5) and the value to "-1.570795" (-π/2).

之后删除额外的/即可
number

<强>测试

enter image description here