Creating XML document using DOM


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Creating XML document using DOM

Hybrid View

  1. #1
    Gee Guest

    Creating XML document using DOM


    How to create XML document using DOM?
    Any sample or link will be a great help


    Thanks

  2. #2
    Jaco de Villiers Guest

    Re: Creating XML document using DOM


    Use the following code snipped as an example:

    On Error GoTo CreateScreenHeaderERR

    Dim oParentElement As MSXML2.IXMLDOMNode
    Dim oElement As MSXML2.IXMLDOMNode
    Dim oAttribute As MSXML2.IXMLDOMAttribute
    Dim oNodeMAP As MSXML2.IXMLDOMNamedNodeMap

    '/// Clear the XML object
    Set oXML = New MSXML2.DOMDocument40

    '/// Set the XML loading state variables
    oXML.async = False
    oXML.preserveWhiteSpace = True
    oXML.validateOnParse = True

    '/// Load XML header info
    oXML.loadXML "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & "<screen>"
    & vbCrLf & "</screen>"

    '/// Start loading the screen header info
    '/// === screen
    Set oParentElement = oXML.selectSingleNode("screen")

    '/// screen attributes
    '/// === code
    Set oAttribute = oXML.createNode(NODE_ATTRIBUTE, "code", "")
    oAttribute.Text = sScreenName
    Set oNodeMAP = oParentElement.Attributes
    oNodeMAP.setNamedItem oAttribute

    '/// screen children
    '/// === screenname
    Set oElement = oXML.createNode(NODE_ELEMENT, "screenname", "")
    oElement.Text = sScreenName
    oParentElement.appendChild oElement

    '/// === screendesc
    Set oElement = oXML.createNode(NODE_ELEMENT, "screendesc", "")
    oElement.Text = sScreenDesc
    oParentElement.appendChild oElement

    '/// === processid
    Set oElement = oXML.createNode(NODE_ELEMENT, "processid", "")
    oElement.Text = lProcessID
    oParentElement.appendChild oElement

    '/// === workitemtypeid
    Set oElement = oXML.createNode(NODE_ELEMENT, "workitemtypeid", "")
    oElement.Text = lWorkItemTypeID
    oParentElement.appendChild oElement

    '/// === mode
    Set oElement = oXML.createNode(NODE_ELEMENT, "mode", "")
    oElement.Text = iMode
    oParentElement.appendChild oElement

    '/// === fields
    Set oElement = oXML.createNode(NODE_ELEMENT, "fields", "")
    oParentElement.appendChild oElement

    '/// === workitemdesc
    Set oElement = oXML.createNode(NODE_ELEMENT, "workitemdesc", "")
    oElement.Text = sWorkItemDesc
    oParentElement.appendChild oElement

    '/// === screenpic
    Set oElement = oXML.createNode(NODE_ELEMENT, "screenpic", "")
    Set oParentElement = oParentElement.appendChild(oElement)

    '/// === screenpic === picx1
    Set oElement = oXML.createNode(NODE_ELEMENT, "x1", "")
    oElement.Text = lPicX1
    oParentElement.appendChild oElement

    '/// === screenpic === picx2
    Set oElement = oXML.createNode(NODE_ELEMENT, "x2", "")
    oElement.Text = lPicX2
    oParentElement.appendChild oElement

    '/// === screenpic === picy1
    Set oElement = oXML.createNode(NODE_ELEMENT, "y1", "")
    oElement.Text = lPicY1
    oParentElement.appendChild oElement

    '/// === screenpic === picy2
    Set oElement = oXML.createNode(NODE_ELEMENT, "y2", "")
    oElement.Text = lPicY2
    oParentElement.appendChild oElement

    '/// === screenpic === picy2
    Set oElement = oXML.createNode(NODE_ELEMENT, "http_reference", "")
    oElement.Text = sPicRef
    oParentElement.appendChild oElement

    Set CreateScreenHeader = oXML

    CreateScreenHeaderERR:
    '/// CleanUp
    Set oParentElement = Nothing
    Set oElement = Nothing
    Set oAttribute = Nothing
    Set oNodeMAP = Nothing

    If Not Err.Number = 0 Then
    Err.Raise Err.Number, "ScreenGenerator.CreateScreenHeader()", Err.Source
    & vbCrLf & Err.Description
    End If



    "Gee" <grajput@slk.com> wrote:
    >
    >How to create XML document using DOM?
    >Any sample or link will be a great help
    >
    >
    >Thanks



  3. #3
    Gee Guest

    Re: Creating XML document using DOM


    Thanks.

    "Jaco de Villiers" <jacodv_32@hotmail.com> wrote:
    >
    >Use the following code snipped as an example:
    >
    > On Error GoTo CreateScreenHeaderERR
    >
    > Dim oParentElement As MSXML2.IXMLDOMNode
    > Dim oElement As MSXML2.IXMLDOMNode
    > Dim oAttribute As MSXML2.IXMLDOMAttribute
    > Dim oNodeMAP As MSXML2.IXMLDOMNamedNodeMap
    >
    > '/// Clear the XML object
    > Set oXML = New MSXML2.DOMDocument40
    >
    > '/// Set the XML loading state variables
    > oXML.async = False
    > oXML.preserveWhiteSpace = True
    > oXML.validateOnParse = True
    >
    > '/// Load XML header info
    > oXML.loadXML "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & "<screen>"
    >& vbCrLf & "</screen>"
    >
    > '/// Start loading the screen header info
    > '/// === screen
    > Set oParentElement = oXML.selectSingleNode("screen")
    >
    > '/// screen attributes
    > '/// === code
    > Set oAttribute = oXML.createNode(NODE_ATTRIBUTE, "code", "")
    > oAttribute.Text = sScreenName
    > Set oNodeMAP = oParentElement.Attributes
    > oNodeMAP.setNamedItem oAttribute
    >
    > '/// screen children
    > '/// === screenname
    > Set oElement = oXML.createNode(NODE_ELEMENT, "screenname", "")
    > oElement.Text = sScreenName
    > oParentElement.appendChild oElement
    >
    > '/// === screendesc
    > Set oElement = oXML.createNode(NODE_ELEMENT, "screendesc", "")
    > oElement.Text = sScreenDesc
    > oParentElement.appendChild oElement
    >
    > '/// === processid
    > Set oElement = oXML.createNode(NODE_ELEMENT, "processid", "")
    > oElement.Text = lProcessID
    > oParentElement.appendChild oElement
    >
    > '/// === workitemtypeid
    > Set oElement = oXML.createNode(NODE_ELEMENT, "workitemtypeid", "")
    > oElement.Text = lWorkItemTypeID
    > oParentElement.appendChild oElement
    >
    > '/// === mode
    > Set oElement = oXML.createNode(NODE_ELEMENT, "mode", "")
    > oElement.Text = iMode
    > oParentElement.appendChild oElement
    >
    > '/// === fields
    > Set oElement = oXML.createNode(NODE_ELEMENT, "fields", "")
    > oParentElement.appendChild oElement
    >
    > '/// === workitemdesc
    > Set oElement = oXML.createNode(NODE_ELEMENT, "workitemdesc", "")
    > oElement.Text = sWorkItemDesc
    > oParentElement.appendChild oElement
    >
    > '/// === screenpic
    > Set oElement = oXML.createNode(NODE_ELEMENT, "screenpic", "")
    > Set oParentElement = oParentElement.appendChild(oElement)
    >
    > '/// === screenpic === picx1
    > Set oElement = oXML.createNode(NODE_ELEMENT, "x1", "")
    > oElement.Text = lPicX1
    > oParentElement.appendChild oElement
    >
    > '/// === screenpic === picx2
    > Set oElement = oXML.createNode(NODE_ELEMENT, "x2", "")
    > oElement.Text = lPicX2
    > oParentElement.appendChild oElement
    >
    > '/// === screenpic === picy1
    > Set oElement = oXML.createNode(NODE_ELEMENT, "y1", "")
    > oElement.Text = lPicY1
    > oParentElement.appendChild oElement
    >
    > '/// === screenpic === picy2
    > Set oElement = oXML.createNode(NODE_ELEMENT, "y2", "")
    > oElement.Text = lPicY2
    > oParentElement.appendChild oElement
    >
    > '/// === screenpic === picy2
    > Set oElement = oXML.createNode(NODE_ELEMENT, "http_reference", "")
    > oElement.Text = sPicRef
    > oParentElement.appendChild oElement
    >
    > Set CreateScreenHeader = oXML
    >
    >CreateScreenHeaderERR:
    > '/// CleanUp
    > Set oParentElement = Nothing
    > Set oElement = Nothing
    > Set oAttribute = Nothing
    > Set oNodeMAP = Nothing
    >
    > If Not Err.Number = 0 Then
    > Err.Raise Err.Number, "ScreenGenerator.CreateScreenHeader()", Err.Source
    >& vbCrLf & Err.Description
    > End If
    >
    >
    >
    >"Gee" <grajput@slk.com> wrote:
    >>
    >>How to create XML document using DOM?
    >>Any sample or link will be a great help
    >>
    >>
    >>Thanks

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center