troubleshooting Question

MSXML2.DOMDocument documentElement-Question

Avatar of chriswies
chriswies asked on
XMLMicrosoft DevelopmentEditors IDEs
4 Comments1 Solution1097 ViewsLast Modified:
Why can't I read the document content??

All is working fine when working with ascii-charset.
But I need to store a RC4 string in the xml-File. Then
   
    Dim xmlRoot As MSXML2.IXMLDOMNode
    Dim xmlDoc As New MSXML2.
    xmlDoc.Load
    Set xmlRoot = xmlDoc.documentElement()  --> stays NOTHING


I tried to create the file on different ways but nothing helped. I'm convinced that I am totally on the wrong track.
Does anybody has an idea? How do I have to handle encoding here?
Chris

These are the 3 ways I checked out concerning file creation
#1
    Open strFullFileName For Output As #lngFileNum
    Print #lngFileNum, strText
    Close #lngFileNum

#2    
    Dim stm As ADODB.Stream
    Dim strpath As String
    strpath = strFullFileName
    Set stm = New ADODB.Stream
    stm.Open
    stm.Charset = "UTF-8"
    stm.WriteText strText, adWriteChar
    stm.SaveToFile strpath, adSaveCreateOverWrite


#3
    Dim docOut As MSXML2.DOMDocument
    Dim domPI As MSXML2.IXMLDOMProcessingInstruction
    Dim eleRoot As MSXML2.IXMLDOMElement
    Dim eleChild As MSXML2.IXMLDOMElement
    Dim strpath As String
    Dim i As Long
    Dim varvalue As Variant
   
    Set docOut = New MSXML2.DOMDocument
    Set domPI = docOut.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'")
    docOut.appendChild domPI
   
    Set eleRoot = docOut.createElement("data")
    docOut.appendChild eleRoot
   
   
    For i = 0 To UBound(varData)
        varvalue = varData(i)
        Set eleChild = eleRoot.appendChild(docOut.createElement(varvalue(0)))
        eleChild.Text = varvalue(1)
    Next i

    strpath = "Y:\MyDocuments\hfp\02 Prüfungsmanager\Version 4.0\asdf.xml"
    On Error Resume Next
    Kill strpath
    docOut.Save strpath



Give it a try:
This one failes
<?xml version="1.0" encoding="UTF-8"?>
<data><ADO>ó!¬â¡Cê¸TþHâ©dû¼R¿709-ç </ADO><ODBC>ó!¬â¡Cê¸TþHâ©dû¼R¿709-ç </ODBC></data>

This one succeeds
<?xml version="1.0" encoding="UTF-8"?>
<data><ADO>myString</ADO><ODBC>mySting2</ODBC></data>

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros