请帮我在visual basic(Excel宏)中创建一个包含以下内容的xml文件 我需要知道如何将属性添加到HPAppBuilder节点,如下所示。
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<HPAppBuilder xml:base="" localizationType="embedded" version="1.0" xmlns="http://www.hp.com/schemas/sbs/pnc/2010/12/9">
</HPAppBuilder>
答案 0 :(得分:1)
<强>更新强> 如果你真的需要完整的XML功能,你需要使用XML DOM创建xml文档,这是一项相当多的工作,而不是一些简单的字符串操作:http://msdn.microsoft.com/en-us/library/aa468547.aspx
否则,只是:
Dim xml As String
xml = "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes"" ?>" & vbCrLf & _
"<HPAppBuilder xml:base="""" localizationType=""embedded"" version=""1.0"" xmlns=""http://www.hp.com/schemas/sbs/pnc/2010/12/9""> " & vbCrLf & _
"</HPAppBuilder>"
Open "c:\myfile.xml" For Output As #1
Print #1, xml
Close #1
答案 1 :(得分:1)
试试这个:
Dim doc = CreateObject("MSXML2.DOMDocument");
Dim appBuilder = doc.CreateElement("HPAppBuilder")
appBuilder.SetAttribute "xml:base", ""
appBuilder.SetAttribute "localizationType", "embedded"
appBuilder.SetAttribute "version", "1.0"
appBuilder.SetAttribute "xmlns", "http://www.hp.com/schemas/sbs/pnc/2010/12/9"
doc.AppendChild appBuilder
doc.Save "c:\myfile.xml"