Author Topic: MSXML Examples  (Read 91703 times)

0 Members and 1 Guest are viewing this topic.

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createAttribute Method
« Reply #15 on: September 02, 2011, 12:26:17 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the createAttribute method.
' The following example creates a new attribute called ID and adds it to the attributes of
' the DOMDocument object.
' =========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' =========================================================================================
' Main
' =========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pNamedNodeMap AS IXMLDOMNamedNodeMap
   LOCAL pNewAtt AS IXMLDOMAttribute
   LOCAL i AS LONG

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         pNewAtt = pXmlDoc.createAttribute("ID")
         pNamedNodeMap = pRootNode.attributes
         pNamedNodeMap.setNamedItem(pNewAtt)
         FOR i = 0 TO pNamedNodeMap.length - 1
            AfxShowMsg pNamedNodeMap.item(i).xml
         NEXT
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' =========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createCDataSection Method
« Reply #16 on: September 02, 2011, 12:26:56 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of createCDATASection.
' The following example creates a new CDATA section node.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pNodeCDATA AS IXMLDOMCDATASection

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   pNodeCDATA = pXmlDoc.createCDATASection("Hello")
   AfxShowMsg pNodeCDATA.Xml

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createComment Method
« Reply #17 on: September 02, 2011, 12:29:14 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of createComment and appendChild.
' The following example creates a new comment node and appends it as the last child node
' of the DOMDocument object.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pParseError AS IXMLDOMParseError
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pComment AS IXMLDOMComment

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         pComment = pXmlDoc.createComment("Hello World!")
         pRootNode.appendChild pComment
         AfxShowMsg pRootNode.Xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createDocumentFragment Method
« Reply #18 on: September 02, 2011, 12:29:58 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of createDocumentFragment.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pDocFragment AS IXMLDOMDocumentFragment
   LOCAL pRootNode AS IXMLDOMElement

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.loadXML("<root/>")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pDocFragment = pXmlDoc.createDocumentFragment
         pDocFragment.AppendChild pXmlDoc.createElement("node1")
         pDocFragment.AppendChild pXmlDoc.createElement("node2")
         pDocFragment.AppendChild pXmlDoc.createElement("node3")
         AfxShowMsg pDocFragment.xml
         ' PB doesn't allow...
         ' pXmlDoc.documentElement.appendChild pDocFragment
         ' .. so we have to use an intermediate step...
         pRootNode = pXmlDoc.documentElement
         pRootNode.appendChild pDocFragment
         AfxShowMsg pXmlDoc.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createElement Method
« Reply #19 on: September 02, 2011, 12:30:56 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the createElement method.
' The following example creates an element called PAGES and appends it to an IXMLDOMNode
' object. It then sets the text value of the element to 400.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pNewElem AS IXMLDOMElement
   LOCAL pDOMNode AS IXMLDOMNode

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         pNewElem = pXmlDoc.createElement("PAGES")
         pDOMNode = pRootNode.childNodes.item(1)
         pDOMNode.appendChild pNewElem
         pDOMNode.lastChild.text = "400"
         AfxShowMsg pDOMNode.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Code: [Select]
' ========================================================================================
' Demonstrates the use of the createElement method.
' The following example creates an element called NEW and appends it to an IXMLDOMNode
' object. It then sets the text value of the element to 123.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pNewElem AS IXMLDOMElement

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.loadXML("<root><child/></root>")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         pNewElem = pXmlDoc.createElement("NEW")
         pRootNode.childnodes.item(0).appendChild(pNewElem)
         pRootNode.childnodes.item(0).lastChild.text = "123"
         AfxShowMsg pRootNode.childNodes.item(0).xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createEntryReference Method
« Reply #20 on: September 02, 2011, 12:31:55 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of createEntityReference.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pNodeEntityReference AS IXMLDOMEntityReference
   LOCAL pRootNode AS IXMLDOMElement

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmLDoc.loadXML "<root/>"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pNodeEntityReference = pXmlDoc.createEntityReference("nbsp")
         pRootNode = pXmlDoc.documentElement
         pRootNode.appendChild pNodeEntityReference
         AfxShowMsg pXmlDoc.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Code: [Select]
' ========================================================================================
' Demonstrates the use of createEntityReference.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pNodeEntityReference AS IXMLDOMEntityReference
   LOCAL pRootNode AS IXMLDOMElement

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmLDoc.loadXML "<root><child/></root>"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         pNodeEntityReference = pXmlDoc.createEntityReference("newRef")
         pRootNode.childNodes.item(0).appendChild(pNodeEntityReference)
         AfxShowMsg pRootNode.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createNode Method
« Reply #21 on: September 02, 2011, 12:32:57 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the createNode method.
' =========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' =========================================================================================
' Main
' =========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pNewNode AS IXMLDOMNode
   LOCAL pCurrNode AS IXMLDOMNode
   LOCAL pLastChild AS IXMLDOMNode

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmLDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         AfxShowMsg pRootNode.xml
         pNewNode = pXmlDoc.createNode(%NODE_ELEMENT, "VIDEOS", "")
         pLastChild = pRootNode.lastChild
         pCurrNode = pRootNode.insertBefore(pNewNode, pLastChild)
         AfxShowMsg pCurrNode.xml
         AfxShowMsg pRootNode.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' =========================================================================================

Code: [Select]
' =========================================================================================
' Demonstrates the use of the createNode method.
' =========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' =========================================================================================
' Main
' =========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pNewNode AS IXMLDOMNode
   LOCAL pNamedNodeMap AS IXMLDOMNamedNodeMap

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmLDoc.loadXml "<root><child/></root>"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pNewNode = pXmlDoc.createNode(%NODE_ATTRIBUTE, "Sci-Fi", "")
         pNamedNodeMap = pXmlDoc.documentElement.childNodes.item(0).Attributes
         pNamedNodeMap.setNamedItem pNewNode
         AfxShowMsg pXmlDoc.documentElement.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' =========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createProcessingInstruction Method
« Reply #22 on: September 02, 2011, 12:51:25 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of createProcessingInstruction.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pPri AS IXMLDOMProcessingInstruction

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   pPri = pXmlDoc.createProcessingInstruction("xml", "version=""1.0""")
   AfxShowMsg pPri.xml

END FUNCTION
' ========================================================================================

Code: [Select]
' ========================================================================================
' Demonstrates the use of createProcessingInstruction.
' The following example specifies the target string "xml" and data string
' "version = '1.0'" to generate the processing instruction <?XML version="1.0"?>.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pPri AS IXMLDOMProcessingInstruction
   LOCAL pNodeList AS IXMLDOMNodeList
   LOCAL pItem AS IXMLDOMNode

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.loadXML "<root><child/></root>"
      pPri = pXmlDoc.createProcessingInstruction("xml", "version=""1.0""")
      pNodeList = pXmlDoc.childNodes
      pItem = pNodeList.item(0)
      pXmlDoc.insertBefore pPri, pItem
      AfxShowMsg pXmlDoc.xml
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createProcessor Method
« Reply #23 on: September 02, 2011, 12:52:42 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the createProcessor method.
' =========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' =========================================================================================
' Main
' =========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pXslt AS IXSLTemplate
   LOCAL pXslDoc AS IXMLDOMDocument
   LOCAL pXslProc AS IXSLProcessor
   LOCAL vOutput AS VARIANT

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION
   pXslt = NEWCOM "Msxml2.XSLTemplate.6.0"
   IF ISNOTHING(pXslt) THEN EXIT FUNCTION
   pXslDoc = NEWCOM "Msxml2.FreeThreadedDOMDocument.6.0"
   IF ISNOTHING(pXslDoc) THEN EXIT FUNCTION

   TRY
      pXslDoc.async = %VARIANT_FALSE
      pXslDoc.load "createProcessor.xsl"
      IF pXslDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXslDoc.parseError.reason
      ELSE
         pXslt.putref_stylesheet = pXslDoc
         pXmlDoc.async = %VARIANT_FALSE
         pXmlDoc.load("books.xml")
         IF pXmlDoc.parseError.errorCode THEN
            AfxShowMsg "You have error " & pXmlDoc.parseError.reason
         ELSE
            pXslProc = pXslt.createProcessor
            pXslProc.input = pXmlDoc
            pXslProc.addParameter "param1", "Hello"
            pXslProc.transform
            vOutput = pXslProc.output
            AfxShowMsg VARIANT$$(vOutput)
         END IF
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' =========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: createTextNode Method
« Reply #24 on: September 02, 2011, 12:53:44 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the createTextNode method.
' =========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' =========================================================================================
' Main
' =========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pTextNode AS IXMLDOMText
   LOCAL pChildNode AS IXMLDOMNode

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.loadXML("<root><child/></root>")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         pTextNode = pXmlDoc.createTextNode("Hello World")
         pChildNode = pRootNode.childNodes.item(0)
         pRootNode.insertBefore pTextNode, pChildNode
         AfxShowMsg pRootNode.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' =========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: data Property (IXMLDOMCharacterData)
« Reply #25 on: September 02, 2011, 12:54:31 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the data (IXMLDOMCharacterData) property.
' The following script example walks the document tree and checks for comment node types.
' If one is found, it displays its contents with the data property.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXMLDoc AS IXMLDOMDocument2
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pDOMNode AS IXMLDOMNode
   LOCAL pComment AS IXMLDOMComment
   LOCAL i AS LONG

   pXMLDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXMLDoc) THEN EXIT FUNCTION

   pXMLDoc.async = %VARIANT_FALSE
   pXMLDoc.loadXML "<root><!-- Hello --></root>"
   IF pXmlDoc.parseError.errorCode THEN
      AfxShowMsg "You have error " & pXmlDoc.parseError.reason
   ELSE
      pRootNode = pXMLDoc.documentElement
      FOR i = 0 TO pRootNode.childNodes.length - 1
         IF pRootNode.childNodes.item(i).nodeType = %NODE_COMMENT THEN
            ' This doesn't work with PB because pRootNode.childNodes.item(i)
            ' returns a pointer to yhe IXMLDOMNode interface, not a pointer
            ' to the IXMLDOMComment interface.
            ' pComment = pRootNode.childNodes.item(i)
            ' MSGBOX pComment.Data
            ' Therefore, we need assign it to an object variable declared as
            ' IXMLDOMNode and then assign it to pComment, forcing an implicit
            ' call to QueryInterface to retrieve the correct object pointer.
            pDOMNode = pRootNode.childNodes.item(i)
            pComment = pDOMNode
            AfxShowMsg pComment.Data
         END IF
      NEXT
   END IF

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: data Property (IXMLDOMProcessingInstruction)
« Reply #26 on: September 02, 2011, 12:55:09 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the data (IXMLDOMProcessingInstruction) property.
' The following example displays the node's data of the xml processing instruction.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument2
   LOCAL pDOMNode AS IXMLDOMNode
   LOCAL pri AS IXMLDOMProcessingInstruction

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pDOMNode = pXMLDoc.firstChild
         IF pDOMNode.nodeType = %NODE_PROCESSING_INSTRUCTION THEN
            pri = pDOMNode
            AfxShowMsg pri.Data
            pri = NOTHING
         END IF
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: dataType Property
« Reply #27 on: September 02, 2011, 12:55:59 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the dataType property.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXMLDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement

   pXMLDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXMLDoc) THEN EXIT FUNCTION

   TRY
      pXMLDoc.async = %VARIANT_FALSE
      pXMLDoc.loadXML("<root/>")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXMLDoc.documentElement
         pRootNode.dataType = "int"
         pRootNode.nodeTypedValue = 5
         AfxShowMsg pXMLDoc.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: definition Property
« Reply #28 on: September 02, 2011, 12:56:38 AM »
Code: [Select]
' ========================================================================================
' The following example shows the retrieval of the definition property from an
' IXMLDOMElement.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument2
   LOCAL pIXMLDOMElement AS IXMLDOMElement
   LOCAL pIXMLDOMNode AS IXMLDOMNode

   ' XDR schemas are not supported in MSXML 6.0.
   ' Therefore, we must use version 3.0 or 4.0.
   pXmlDoc = NEWCOM "Msxml2.DOMDocument.4.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load "sample.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pIXMLDOMElement = pXMLDoc.documentElement
         pIXMLDOMNode = pIXMLDOMElement.definition
         IF ISOBJECT(pIXMLDOMNode) THEN AfxShowMsg pIXMLDOMNode.xml
         ' Note: The first two lines above can be replaced by:
         ' pIXMLDOMNode = pXmlDoc.documentElement.definition
         ' And the three lines above can be replaced by:
         ' AfxShowMsg pXmlDoc.documentElement.definition.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Online José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: deleteData Method
« Reply #29 on: September 02, 2011, 12:57:22 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the deleteData method.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pComment AS IXMLDOMComment

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load("books.xml")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pComment = pXmlDoc.createComment("Hello World!")
         pComment.deleteData 6, 6
         AfxShowMsg pComment.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================

Code: [Select]
' ========================================================================================
' Demonstrates the use of the deleteData method.
' The following example creates an IXMLDOMComment object and uses the deleteData method to
' delete three characters of data starting after the third character in data for the
' IXMLDOMComment object.
' ========================================================================================

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "msxml.inc"
#INCLUDE ONCE "ole2utils.inc"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pComment AS IXMLDOMComment

   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDOc.loadXML("<root><child/></root>")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pComment = pXmlDoc.createComment("123456789")
         pComment.deleteData 3, 3
         AfxShowMsg pComment.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

END FUNCTION
' ========================================================================================