While creating the XML document, MXXMLWriter40 does not check if the document is well-formed, valid, or support namespaces. It simply writes the details based on the event methods called on it. In other words, there is no direct support for creating elements with namespaces. The workaround is to manually create the namespace declarations as attributes.
The following VB 6.0 code uses MSXML 4.0 and illustrates how to create an XML document using MXXMLWriter40 - the generated XML document contains elements with namespace declaration.
Dim writer As New MXXMLWriter40
Dim CH As IVBSAXContentHandler
Dim attrib As New SAXAttributes40
writer.encoding = "UTF-8"
writer.indent = True
Set CH = writer
CH.startDocument
attrib.addAttribute "", "myNS", "xmlns:myNS", "", "http://testuri"
CH.startElement "http://testuri", "WebSites", "myNS:WebSites", attrib
CH.characters "perfectxml.com"
CH.endElement "http://testuri", "WebSites", "myNS:WebSites"
CH.endDocument
Debug.Print writer.output
MsgBox writer.output The above Visual Basic code generates the following XML:
<?xml version="1.0" standalone="no"?>
<myNS:WebSites xmlns:myNS="http://testuri">perfectxml.com</myNS:WebSites>
Related Links:
|