Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operations on XML Elements 1

Status
Not open for further replies.

patriciaxxx

Programmer
Jan 30, 2012
277
GB
I have the following code

Code:
[COLOR=#204A87]Private Sub cmdAppendElement_Click()
Dim docXMLDOM  As DOMDocument
Dim nodElement As IXMLDOMElement
Dim nodChild As IXMLDOMElement

Set docXMLDOM = New DOMDocument

Set nodElement = docXMLDOM.createElement("videos")
Set docXMLDOM.documentElement = nodElement

Set nodChild = docXMLDOM.createElement("video")
nodElement.appendChild nodChild

docXMLDOM.Save CurrentProject.Path & "\videos12.xml"

Set docXMLDOM = Nothing
End Sub
[/color]

Which should produce this

Code:
<?xml version="1.0"?>
<videos>
  <video></video>
</videos>

But for me it produces this

Code:
<videos>
  <video /> 
</videos>

How do I get it to produce this

Code:
<?xml version="1.0"?>
<videos>
  <video></video>
</videos>
 
Does this help?

Code:
' 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

taken from :

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Both

[tt]<video />[/tt]

and

[tt]<video></video>[/tt]

are legitimate expressions of empty elements (the XML specification says “The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag") and by default Microsoft's XML uses the empty-element tag, as you have discovered.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top