在XML中将XML文件转换为String变量(Convert XML file to String variable in VBA)

编程入门 行业动态 更新时间:2024-10-22 21:19:29
在XML中将XML文件转换为String变量(Convert XML file to String variable in VBA)

我希望将XML文件的内容转换为excel VBA中的String变量,以便我可以在文件中搜索特定的字符串。

但是我不知道如何从XML文件到String变量进行初始转换。 到目前为止,我所能做的就是加载XML文档,从那里我就被卡住了。

Public Function DetermineSpecifiedChange(ByVal vstrInputGBOMPath As String, ByVal vstrInputPDPPath As String) Dim strPDPString As String Dim strGBOMString As String Dim xmlGBOM As New DOMDocument60 Dim xmlPDP As New DOMDocument60 strPDPString = xmlPDP.Load(vstrInputPDPPath) End Function

到目前为止,所有这些返回都是“True”,表示正在加载文件。

我如何将XML文件转换为字符串?

I'm looking to convert the contents of an XML file into a String variable in excel VBA so that I can search the file for a specific string.

However I don't know how to do the initial conversion from XML file to String variable. All I've been able to do so far is load the XML document, and from there I'm stuck.

Public Function DetermineSpecifiedChange(ByVal vstrInputGBOMPath As String, ByVal vstrInputPDPPath As String) Dim strPDPString As String Dim strGBOMString As String Dim xmlGBOM As New DOMDocument60 Dim xmlPDP As New DOMDocument60 strPDPString = xmlPDP.Load(vstrInputPDPPath) End Function

So far all this returns is "True", signifying that the file is being loaded.

How would I go about converting the XML file into a string?

最满意答案

这是一种做你要求的方法:

Dim FSO As Object : Set FSO = CreateObject("Scripting.FileSystemObject") Dim strXml As String strXml = FSO.OpenTextFile("C:\myfile.xml").ReadAll

Here's a way to do what you ask:

Dim FSO As Object : Set FSO = CreateObject("Scripting.FileSystemObject") Dim strXml As String strXml = FSO.OpenTextFile("C:\myfile.xml").ReadAll

更多推荐

XML,String,file,Function,文件,电脑培训,计算机培训,IT培训"/> <meta name="d

本文发布于:2023-07-20 02:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1192109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   变量   文件   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!