nr.iras.sk
nr.iras.sk

Reputation: 8498

Xml creation in Visual Basic for Applications

Please help me to create an xml file with following content in visual basic(Excel macro) I need to know how can I add the attributes to HPAppBuilder node as given below.

<?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>

Upvotes: 0

Views: 1901

Answers (2)

Rubens Farias
Rubens Farias

Reputation: 57976

Try this:

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"

Upvotes: 1

Dan Bystr&#246;m
Dan Bystr&#246;m

Reputation: 9244

UPDATE: If you really need full XML capabilites you need to create the xml document using the XML DOM, which is quite a bit of work, as opposed to some simple string manipulations: http://msdn.microsoft.com/en-us/library/aa468547.aspx

Otherwise, just:

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

Upvotes: 1

Related Questions