Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Why I cannot use the following code inside VBA in MS word? What should I do if I want to make that work?

$
0
0
PrivateFunction CreateDOM()Dim domSet dom = New DOMDocument60
    dom.async = False
    dom.validateOnParse = False
    dom.resolveExternals = False
    dom.preserveWhiteSpace = TrueSet CreateDOM = domEndFunctionPrivateSub Form_Load()Dim dom, node, attrOnErrorGoTo ErrorHandlerSet dom = CreateDOM' Create a processing instruction targeted for xml.Set node = dom.createProcessingInstruction("xml", "version='1.0'")
    dom.appendChild nodeSet node = Nothing' Create a processing instruction targeted for xml-stylesheet.Set node = dom.createProcessingInstruction("xml-stylesheet", _"type='text/xml' href='test.xsl'")
    dom.appendChild nodeSet node = Nothing' Create a comment for the document.Set node = dom.createComment("sample xml file created using XML DOM object.")
    dom.appendChild nodeSet node = Nothing' Create the root element.Dim rootSet root = dom.createElement("root")' Create a "created" attribute for the root element and' assign the "using dom" character data as the attribute value.Set attr = dom.createAttribute("created")
    attr.Value = "using dom"
    root.setAttributeNode attrSet attr = Nothing' Add the root element to the DOM instance.
    dom.appendChild root' Insert a newline + tab.
    root.appendChild dom.createTextNode(vbNewLine + vbTab)' Create and add more nodes to the root element just created.' Create a text element.Set node = dom.createElement("node1")
    node.Text = "some character data"' Add text node to the root element.
    root.appendChild nodeSet node = Nothing' Add a newline plus tab.
    root.appendChild dom.createTextNode(vbNewLine + vbTab)' Create an element to hold a CDATA section.Set node = dom.createElement("node2")Set cd = dom.createCDATASection("<some mark-up text>")
    node.appendChild cdSet cd = Nothing
    dom.documentElement.appendChild nodeSet node = Nothing' Add a newline plus tab.
    root.appendChild dom.createTextNode(vbNewLine + vbTab)' Create an element to hold three empty subelements.Set node = dom.createElement("node3")' Create a document fragment to be added to node3.Set frag = dom.createDocumentFragment' Add a newline + tab + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
    frag.appendChild dom.createElement("subNode1")' Add a newline + tab + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
    frag.appendChild dom.createElement("subNode2")' Add a newline + tab + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
    frag.appendChild dom.createElement("subNode3")' Add a newline + tab.
    frag.appendChild dom.createTextNode(vbNewLine + vbTab)
    node.appendChild fragSet frag = Nothing

    root.appendChild node
       ' Add a newline.
    root.appendChild dom.createTextNode(vbNewLine)Set node = Nothing' Save the XML document to a file.
    dom.save App.Path + "\dynamDom.xml"Set root = NothingSet dom = NothingExitSub

ErrorHandler:
    MsgBox Err.Description
EndSub

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>