[
Lists Home |
Date Index |
Thread Index
]
Actually, MSXML is doing the right thing, here. XML 1.0 explicitly disallows
such characters in content -- even if they are encoded.
One workaround is to define application-specific tags for conveying such
characters, e.g. <char code="1"/>. You can then translate these tags into
the corresponding characters when retrieving the content from the XML.
> -----Original Message-----
> From: Mark Tucker [mailto:MTucker@infoimage.com]
> Sent: Thursday, March 21, 2002 2:54 PM
> To: xml-dev@lists.xml.org
> Subject: [xml-dev] MSXML DOM Special Chars Less Than 32
>
>
> We are having trouble encoding special characters less than
> 32 (excluding 9, 10, and 13). One server is creating an XML
> DOM and returning the XML as a string. The calling server is
> then getting this XML string and loading it into a DOM. The
> following VB test app shows that assigning a special
> character to the Text property doesn't encode it in a way
> that a later call to loadXML will work:
>
> Dim xmldoc As MSXML2.DOMDocument
> Dim xmldoc2 As MSXML2.DOMDocument
> Dim strXML As String
>
> For x = 1 To 255
> Set xmldoc = New MSXML2.DOMDocument
>
> Set pi = xmldoc.createProcessingInstruction("xml", "
> version='1.0'")
> xmldoc.appendChild pi
>
> Set e = xmldoc.createElement("test")
> e.Text = "chr(" & x & ")=" & Chr(x) & ";"
> xmldoc.appendChild e
>
> strXML = CStr(xmldoc.xml)
>
> Set xmldoc2 = New MSXML2.DOMDocument
> xmldoc2.loadXML strXML
>
> If xmldoc2.parseError.errorCode <> 0 Then
> Debug.Print x, "parseError:" & xmldoc2.parseError.reason
> End If
>
> Set xmldoc = Nothing
> Set xmldoc2 = Nothing
> Next
>
>
> The output is:
>
> 1 parseError:An invalid character was found in
> text content.
> 2 parseError:An invalid character was found in
> text content.
> 3 parseError:An invalid character was found in
> text content.
> 4 parseError:An invalid character was found in
> text content.
> 5 parseError:An invalid character was found in
> text content.
> 6 parseError:An invalid character was found in
> text content.
> 7 parseError:An invalid character was found in
> text content.
> 8 parseError:An invalid character was found in
> text content.
> 11 parseError:An invalid character was found in
> text content.
> 12 parseError:An invalid character was found in
> text content.
> 14 parseError:An invalid character was found in
> text content.
> 15 parseError:An invalid character was found in
> text content.
> 16 parseError:An invalid character was found in
> text content.
> 17 parseError:An invalid character was found in
> text content.
> 18 parseError:An invalid character was found in
> text content.
> 19 parseError:An invalid character was found in
> text content.
> 20 parseError:An invalid character was found in
> text content.
> 21 parseError:An invalid character was found in
> text content.
> 22 parseError:An invalid character was found in
> text content.
> 23 parseError:An invalid character was found in
> text content.
> 24 parseError:An invalid character was found in
> text content.
> 25 parseError:An invalid character was found in
> text content.
> 26 parseError:An invalid character was found in
> text content.
> 27 parseError:An invalid character was found in
> text content.
> 28 parseError:An invalid character was found in
> text content.
> 29 parseError:An invalid character was found in
> text content.
> 30 parseError:An invalid character was found in
> text content.
> 31 parseError:An invalid character was found in
> text content.
>
>
> I tried playing with the encoding on the initial DOM
> document, but it has no effect.
>
> How do I properly encode these special characters?
>
> Mark Tucker
> mtucker@infoimage.com
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
|