Author Topic: MSXML Examples  (Read 91702 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: notations Property
« Reply #90 on: September 02, 2011, 03:06:21 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the notations property.
' ========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pNamedNodeMap AS IXMLDOMNamedNodeMap
   LOCAL pDocType AS IXMLDOMDocumentType
   LOCAL pDomNode AS IXMLDOMNode
   LOCAL pNotation AS IXMLDOMNotation
   LOCAL vPublicId AS VARIANT

   ' DTDs are disabled by default in version 6.0
   pXmlDoc = NEWCOM "Msxml2.DOMDocument.4.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load "doment1.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pDocType = pXmlDoc.doctype
         pNamedNodeMap = pDocType.notations
         pDOMNode = pNamedNodeMap.nextNode
         pNotation = pDOMNode
         vPublicId = pNotation.systemId
         AfxShowMsg VARIANT$$(vPublicId)
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

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

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument2
   LOCAL pNamedNodeMap AS IXMLDOMNamedNodeMap
   LOCAL pDocType AS IXMLDOMDocumentType
   LOCAL pDomNode AS IXMLDOMNode
   LOCAL pNotation AS IXMLDOMNotation
   LOCAL vPublicId AS VARIANT

   ' DTDs are disabled by default in version 6.0
   pXmlDoc = NEWCOM "Msxml2.DOMDocument.6.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.setProperty "ProhibitDTD", %VARIANT_FALSE
      pXmlDoc.load "doment1.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pDocType = pXmlDoc.doctype
         pNamedNodeMap = pDocType.notations
         pDOMNode = pNamedNodeMap.nextNode
         pNotation = pDOMNode
         vPublicId = pNotation.systemId
         AfxShowMsg VARIANT$$(vPublicId)
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: output Property
« Reply #91 on: September 02, 2011, 03:07:09 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the output property.
' ========================================================================================

#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 vRes 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
      IF ISTRUE pXslDoc.load("Sample2.xsl") THEN
         pXslt.putref_stylesheet = pXslDoc
         pXmlDoc.async = %FALSE
         IF ISTRUE pXmlDoc.load("books.xml") THEN
            pXslProc = pXslt.createProcessor
            pXslProc.input = pXmlDoc
            pXslProc.transform
            vRes = pXslProc.output
            AfxShowMsg VARIANT$$(vRes)
         END IF
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: ownerDocument Property
« Reply #92 on: September 02, 2011, 03:07:57 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the ownerDocument property.
' The following example uses the ownerDocument property to return the parent DOMDocument
' object, and then displays that object's root element tag name.
' ========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pDocElem1 AS IXMLDOMElement
   LOCAL pDocElem2 AS IXMLDOMElement
   LOCAL pChildNodes1 AS IXMLDOMNodeList
   LOCAL pChildNodes2 AS IXMLDOMNodeList
   LOCAL pItem1 AS IXMLDOMNode
   LOCAL pItem2 AS IXMLDOMNode
   LOCAL pCurrNode AS IXMLDOMNode
   LOCAL pOwner AS IXMLDOMDocument

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

   pXmlDoc.async = %VARIANT_FALSE
   IF ISTRUE pXmlDoc.load("books.xml") THEN
      pDocElem1 = pXmlDoc.documentElement
      pChildNodes1 = pDocElem1.childNodes
      pItem1 = pChildNodes1.item(0)
      pChildNodes2 = pItem1.childNodes
      pItem2 = pChildNodes2.item(1)
      pOwner = pItem2.ownerDocument
      pDocElem2 = pOwner.documentElement
      AfxShowMsg pDocElem2.tagName
   END IF

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: ownerTemplate Property
« Reply #93 on: September 02, 2011, 03:08:32 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the ownerTemplate property.
' ========================================================================================

#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 pTemplate AS IXSLTemplate
   LOCAL pStyleSheet AS IXMLDOMNode

   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

   pXmlDoc.async = %VARIANT_FALSE
   IF ISTRUE pXslDoc.load("sample2.xsl") THEN
      pXslt.putref_stylesheet = pXslDoc
      pXmlDoc.async = %FALSE
      IF ISTRUE pXmlDoc.load("books.xml") THEN
         pXslProc = pXslt.createProcessor
         pTemplate = pXslProc.ownerTemplate
         pStyleSheet = pTemplate.stylesheet
         AfxShowMsg pStyleSheet.xml
      END IF
   END IF

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: parentNode Property
« Reply #94 on: September 02, 2011, 03:10:50 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the parentNode property.
' The following example sets a variable ('pParentNode') to reference the parent node of
' another IXMLDOMNode object ('pChildNode'). It then uses the reference to the new node to
' display the XML contents of its parent node.
' =========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pCurrNode AS IXMLDOMNode
   LOCAL pParentNode AS IXMLDOMNode

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

   pXmlDoc.async = %VARIANT_FALSE
   IF ISTRUE pXmlDoc.load("books.xml") THEN
      pRootNode = pXmlDoc.documentElement
      pCurrNode = pRootNode.childNodes.item(1)
      pParentNode = pCurrNode.childNodes.item(0).parentNode
      AfxShowMsg pParentNode.xml
   END IF

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: parsed Property
« Reply #95 on: September 02, 2011, 03:11:30 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the parsed property.
' The following example displays whether the top-level node (root) and all its descendants
' are parsed.
' ========================================================================================

#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.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pRootNode = pXmlDoc.documentElement
         AfxShowMsg STR$(pRootNode.parsed)
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: parseError Property
« Reply #96 on: September 02, 2011, 03:12:34 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the XMLDOMParseError interface.
' ========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument2
   LOCAL pParseError AS IXMLDOMParseError
   LOCAL bstrMsg AS STRING

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

   IF ISFALSE pXmlDoc.load("bad.xml") THEN
      pParseError = pXmlDoc.parseError
      IF ISTRUE ISOBJECT(pParseError) THEN
         bstrMsg  = "-------------------------------------------------------------------------" & $CRLF
         bstrMsg += "Error &H" & HEX$(pParseError.errorCode) & " in the xml file" & $CRLF
         bstrMsg += "-------------------------------------------------------------------------" & $CRLF
         bstrMsg += "Filepos:     " & FORMAT$(pParseError.filePos) & $CRLF
         bstrMsg += "Line:        " & FORMAT$(pParseError.line) & $CRLF
         bstrMsg += "Position:    " & FORMAT$(pParseError.linePos) & $CRLF
         bstrMsg += "Reason:      " & pParseError.reason & $CRLF
         bstrMsg += "Source text: " & pParseError.srcText & $CRLF
         bstrMsg += "Url:         " & pParseError.url & $CRLF
         bstrMsg += "-------------------------------------------------------------------------" & $CRLF
         pParseError = NOTHING
         AfxShowMsg bstrMsg
      END IF
   END IF

   pXmlDoc = NOTHING

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: peekNode Property
« Reply #97 on: September 02, 2011, 03:13:16 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the and peekNode method.
' =========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument2
   LOCAL pNodeBook AS IXMLDOMNode
   LOCAL pSelection AS IXMLDOMSelection

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

   TRY
      pXmlDoc.setProperty "SelectionLanguage", "XPath"
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pSelection = pXmlDoc.selectNodes("//book")
         pNodeBook = pSelection.peekNode
         AfxShowMsg pNodeBook.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: prefix Property
« Reply #98 on: September 02, 2011, 03:13:49 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of prefix property.
' ========================================================================================

#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 bstrNamespaceURI AS WSTRING
   LOCAL i AS LONG

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

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.load "books2.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         ' Get the namespace of the root element.
         pRootNode = pXmlDoc.documentElement
         bstrNamespaceURI = pRootNode.prefix
         AfxShowMsg bstrNamespaceURI
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: preserveWhiteSpace Property
« Reply #99 on: September 02, 2011, 03:14:29 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of preserveWhiteSpace property.
' The following example first loads and displays a file with the preserveWhiteSpace
' property set to True and then reloads and displays the file with the preserveWhiteSpace
' property set to False.
' ========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument

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

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.preserveWhiteSpace = %VARIANT_TRUE
      pXmlDoc.load "books.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         AfxShowMsg pXmlDoc.xml
         pXmlDoc.preserveWhiteSpace = %FALSE
         pXmlDoc.load "books.xml"
         AfxShowMsg pXmlDoc.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: previousSibling Property
« Reply #100 on: September 02, 2011, 03:15:15 AM »
Code: [Select]
' =========================================================================================
' Demonstrates the use of the previousSibling property.
' The following example creates an IXMLDOMNode object and sets it to the previous sibling
' of the current node.
' =========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pRootNode AS IXMLDOMElement
   LOCAL pCurrNode AS IXMLDOMNode
   LOCAL pPrevNode 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
         pCurrNode = pRootNode.childNodes.item(1)
         pPrevNode = pCurrNode.previousSibling
         AfxShowMsg pPrevNode.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: publicId Property (IXMLDOMEntity)
« Reply #101 on: September 02, 2011, 03:17:07 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the publicId property.
' ========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pEntity AS IXMLDOMEntity
   LOCAL pNamedNodeMap AS IXMLDOMNamedNodeMap
   LOCAL pDocType AS IXMLDOMDocumentType
   LOCAL pDOMNode AS IXMLDOMNode
   LOCAL vPublicId AS VARIANT

   ' DTDs are disabled by default in version 6.0
   pXmlDoc = NEWCOM "Msxml2.DOMDocument.4.0"
   IF ISNOTHING(pXmlDoc) THEN EXIT FUNCTION

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmLDoc.load "doment1.xml"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pDocType = pXmlDoc.doctype
         pNamedNodeMap = pDocType.entities
         pDOMNode = pNamedNodeMap.nextNode
         pEntity = pDOMNode
         vPublicID = pEntity.publicID
         AfxShowMsg VARIANT$$(vPublicId)
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Code: [Select]
' ========================================================================================
' Demonstrates the use of the publicId 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 pEntity AS IXMLDOMEntity
   LOCAL pNamedNodeMap AS IXMLDOMNamedNodeMap
   LOCAL pDocType AS IXMLDOMDocumentType
   LOCAL pDOMNode AS IXMLDOMNode
   LOCAL vPublicId AS VARIANT

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

   TRY
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.setProperty "ProhibitDTD", %VARIANT_FALSE
      pXmLDoc.load("doment1.xml")
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         pDocType = pXmlDoc.doctype
         pNamedNodeMap = pDocType.entities
         pDOMNode = pNamedNodeMap.nextNode
         pEntity = pDOMNode
         vPublicID = pEntity.publicID
         AfxShowMsg VARIANT$$(vPublicId)
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: readyState Property (IXSLProcessor)
« Reply #102 on: September 02, 2011, 11:00:07 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the readyState (IXSLProcessor) property.
' Returns the current state of the processor.
' ========================================================================================

#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 iState AS LONG

   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

   pXslDoc.async = %VARIANT_FALSE
   IF ISTRUE pXslDoc.load("sample2.xsl") THEN
      pXslt.putref_stylesheet = pXslDoc
      pXmlDoc.async = %FALSE
      IF ISTRUE pXmlDoc.load("books.xml") THEN
         pXslProc = pXslt.createProcessor
         iState = pXslProc.readyState
         AfxShowMsg "State = " & FORMAT$(iState)
         pXslProc.input = pXmlDoc
         iState = pXslProc.readyState
         AfxShowMsg "State = " & FORMAT$(iState)
      END IF
   END IF

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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
MSXML: reason Property
« Reply #103 on: September 02, 2011, 11:00:45 AM »
Code: [Select]
' ========================================================================================
' Demonstrates the use of the reason property.
' ========================================================================================

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument
   LOCAL pElement AS IXMLDOMElement

   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
         pElement = pXmlDoc.documentElement
         AfxShowMsg pElement.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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

Offline José Roca

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

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

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

   LOCAL pXmlDoc AS IXMLDOMDocument2
   LOCAL pSelection AS IXMLDOMSelection

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

   TRY
      pXmlDoc.setProperty "SelectionLanguage", "XPath"
      pXmlDoc.async = %VARIANT_FALSE
      pXmlDoc.loadXML "<root><child/><child/><child/></root>"
      IF pXmlDoc.parseError.errorCode THEN
         AfxShowMsg "You have error " & pXmlDoc.parseError.reason
      ELSE
         AfxShowMsg "Before removing <child> nodes: " & $CRLF & pXmlDoc.xml
         pSelection = pXmlDoc.selectNodes("//child")
         pSelection.removeAll
         AfxShowMsg "After removing <child> nodes: " & $CRLF & pXmlDoc.xml
      END IF
   CATCH
      AfxShowMsg OleGetErrorInfo(OBJRESULT)
   END TRY

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