55502f40dc8b7c769880b10874abc9d0

Test

' This procedure creates XML document
' and saves it to disk.
' Requires msxml.dll (Go to Project --> References and
' and choose Microsoft XML version 2.0, or whatever the
' current version you have installed)
' The example given below will write the following XML
' documents.
'
' <Family>
'    <Member Relationship="Father">
'       <Name>Some Guy</Name>
'    </Member>
' </Family>
'
'but it should be clear how to modify the code
'to create your own documents

Private Sub Create_XML()
   
   Dim objDom As DOMDocument
   Dim objRootElem As IXMLDOMElement
   Dim objMemberElem As IXMLDOMElement
   Dim objMemberRel As IXMLDOMAttribute
   Dim objMemberName As IXMLDOMElement
   
   Set objDom = New DOMDocument
   
   ' Creates root element
   Set objRootElem = objDom.createElement("Family")
   objDom.appendChild objRootElem
   
   ' Creates Member element
   Set objMemberElem = objDom.createElement("Member")
   objRootElem.appendChild objMemberElem
   
   ' Creates Attribute to the Member Element
   Set objMemberRel = objDom.createAttribute("Relationship")
   objMemberRel.nodeValue = "Father"
   objMemberElem.setAttributeNode objMemberRel
   
   ' Create element under Member element, and
   ' gives value "some guy"
   Set objMemberName = objDom.createElement("Name")
   objMemberElem.appendChild objMemberName
   objMemberName.Text = "Some Guy"

   ' Saves XML data to disk.
   objDom.save ("c:\temp\andrew.xml")
End Sub

Refactorings

No refactoring yet !

F9a9ba6663645458aa8630157ed5e71e

Ants

April 27, 2010, April 27, 2010 23:12, permalink

No rating. Login to rate!

Why instantiate a whole DOM from the imported MSXML, when you can go cheap and use the CLR's XmlTextWriter?

See this article in MSDN: http://msdn.microsoft.com/en-us/library/wkee9k2s(VS.71).aspx

55502f40dc8b7c769880b10874abc9d0

jbrain.myopenid.com

April 28, 2010, April 28, 2010 19:52, permalink

No rating. Login to rate!

Oh! Thank you very much for the tip, I'm a novice programmer. I was tasked with creating xml-files based on the data tables in MS Access. I'll try to do this with XmlTextWriter.

55502f40dc8b7c769880b10874abc9d0

jbrain.myopenid.com

April 28, 2010, April 28, 2010 20:47, permalink

No rating. Login to rate!

@Ants But is is possible to use the XmlTextWriter in the project for MS Access to VBA?

F9a9ba6663645458aa8630157ed5e71e

Ants

April 29, 2010, April 29, 2010 09:14, permalink

No rating. Login to rate!

Your original question was tagged as VB.NET and you made no mention in your description that you needed to do this from VBA.

Anyway, the answer is yes, you can use XmlTextWriter from VBA. See http://msdn.microsoft.com/en-us/library/aa140276(office.10).aspx for an example of using VBA in Word to use the XmlTextWriter. All of Office uses the same VBA code so it should work in Access.

608d21dd57a263e1899bd1bcee284382

Red

February 17, 2011, February 17, 2011 00:22, permalink

No rating. Login to rate!

I am trying to format my xml and was having trouble understanding how to do that with this code?!?!?! can you help?

Thx
Red

F9a9ba6663645458aa8630157ed5e71e

Ants

February 17, 2011, February 17, 2011 17:37, permalink

No rating. Login to rate!

Read here how to do the formatting: http://msdn.microsoft.com/en-us/library/6ts85e64.aspx

2048d0bacf49de14573d887bfb1013ee

web developer

February 24, 2011, February 24, 2011 10:29, permalink

No rating. Login to rate!

Hi,
I found that Andoid application can totally managed using xml specifically for the data driven application having pre-defined database which is being displayed on request. This xml format can be used in that application?

Your refactoring





Format Copy from initial code

or Cancel