获取xml文件的标记名称

时间:2014-08-26 13:54:02

标签: xml vba

由于每次我想读取一个标记由数字和更改组成,但此代码不起作用,我在StrMyXml.nodeName(无效标识符)中收到错误。 目前我的代码是:

Sub Create_XSD()
   Dim StrMyXml As String, MyMap As XmlMap
   Dim StrMySchema As String
   Dim tempString As String
   StrMyXml = "<Translate>"
   StrMyXml = StrMyXml & "<Alarms>"
   tempString = StrMyXml.nodeName
   StrMyXml = StrMyXml & "<" & tempString & ">"
   StrMyXml = StrMyXml & "<Nummer>tempString</Nummer>"
   StrMyXml = StrMyXml & "<Nummer Diagnosename DE>tempString & Text</Nummer Diagnosename DE>"
   StrMyXml = StrMyXml & "<Nummer Diagnosename EN>tempString & Text</Nummer Diagnosename EN>"
   StrMyXml = StrMyXml & "</" & tempString & ">"
   StrMyXml = StrMyXml & "</Alarms>"
   StrMyXml = StrMyXml & "<Alarms></Alarms>"
   StrMyXml = StrMyXml & "</Translate>"
   ' Turn off async loading.
   Application.DisplayAlerts = False
   ' Add the string to the XmlMaps collection.
   Set MyMap = ThisWorkbook.XmlMaps.Add(StrMyXml)
   Application.DisplayAlerts = True

   ' Create an empty file and output the schema.
   StrMySchema = ThisWorkbook.XmlMaps(1).Schemas(1).XML
   Open "D:\Users\F512\Desktop\MySchema.xsd" For Output As #1
   Print #1, StrMySchema
   Close #1
End Sub

感谢每一位帮助!

Laurenz

2 个答案:

答案 0 :(得分:1)

您已将StrMyXml标注为字符串:

Dim StrMyXml As String

但是你试试:

tempString = StrMyXml.nodeName

这不起作用,因为字符串没有这样的属性。

答案 1 :(得分:0)

您已将StrMyXml标注为字符串:

Dim StrMyXml As String

但是你试试:

tempString = StrMyXml.nodeName

这不起作用,因为字符串没有这样的属性。