2

We have an old legacy system that where a component is writter in VB6. One method returns a string that is xml data. The xml data is created with msxml3.dll MSXML2.DOMDocument and returns the data of the document with the property xml: http://msdn.microsoft.com/en-us/library/ms755989(v=VS.85).aspx

However, some data of the xmldocument is from the database and one field is a hashed password string. The code that set the data for the element:

            Set cellNode = rowNode.appendChild(xml.createElement("COL"))
            If IsNull(rs(oField.name).Value) Then
                cellNode.Text = ""
            Else
                cellNode.Text = rs(oField.name).Value
            End If

This gives me malformed/non-wellformed xml:

<ROWS><ROW><COL>r<í</COL></ROW></ROWS>

Is there a workaround for this?

Torbjörn Hansson
  • 18,354
  • 5
  • 33
  • 42
  • Curious. I don't get the same behaviour using `MSXML2.DOMDocument.3.0` via IE `ActiveXObject`. – bobince Nov 09 '10 at 16:36
  • Maybe it's because it's in VB6 and it cannot handle unicode correctly? – Torbjörn Hansson Nov 09 '10 at 16:49
  • VB6 has [incomplete support for Unicode](http://www.i18nwithvb.com/chapters/Chapter06_en.htm) but it shouldn't have any problems with this. VB6 strings are Unicode internally, and when you call MSXML2 via COM the string will stay in Unicode. What happens if you try setting `cellNode.Text` to other strings that contain `<` but no accented characters (stick to characters in ASCII 32-127)? Are there other properties of the cellNode that you could try? – MarkJ Nov 10 '10 at 12:34
  • I tried cellnode.nodeValue and cellNode.appendChild(xml.createCDataSection(rs(oField.name).Value)) (but in that case the output didn't contain any cdata-section at alla) but nothing seems to work. I belive that it's working fine if i'm saving to a file with xml.Save() but haven't tested it. Currently have ported it to .net where it's all fine. – Torbjörn Hansson Nov 10 '10 at 13:03

1 Answers1

0

You should escape unicode characters. Or put them in a CDATA tag (which is not such a nice solution though) Btw < > and & should be escaped as well.

Sjuul Janssen
  • 1,772
  • 1
  • 14
  • 28