-
Creating XML document using DOM
How to create XML document using DOM?
Any sample or link will be a great help
Thanks
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks