为什么nsgmls解析器为utf-8编码文件提供错误“此处不允许使用字符数据”? [英] Why is nsgmls parser giving error “character data not allowed here” for utf-8 encoded file ?

查看:105
本文介绍了为什么nsgmls解析器为utf-8编码文件提供错误“此处不允许使用字符数据”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nsgmls解析器为UTF-8编码文件提供错误此处不允许使用字符数据

我使用以下函数保存文件



nsgmls parser giving error for UTF-8 encoded file "Character Data Not Allowed Here"
I am saving a file using the below function

 Public Function SavetoFile(ByVal p_sFileName As String, ByVal p_sMessage As String, ByVal p_sEncoding As String) As Boolean
    Dim oEncoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(p_sEncoding)
    Dim settings As System.Xml.XmlWriterSettings = New System.Xml.XmlWriterSettings()
    settings.Indent = True
    settings.OmitXmlDeclaration = True
    settings.Encoding = oEncoding
    Using writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(p_sFileName, settings)
        writer.WriteStartDocument()
        writer.WriteRaw(p_sMessage)
        writer.Close()
    End Using
    Return True
End Function



以不同编码保存时的同一文件

案例1:p_sEncoding = SHIFT-JIS - >使用nsgmls.exe验证上面用dtd保存的文件。我没有收到任何错误

case 2:p_sEncoding = UTF-8 - >使用nsgmls.exe验证上面用dtd保存的文件。我收到错误此处不允许使用字符数据

之前用于保存文件的代码如下:




The same file when saved under different encoding
case 1: p_sEncoding=SHIFT-JIS -> using nsgmls.exe validating the file saved above with the dtd .I am not getting any error
case 2: p_sEncoding=UTF-8 -> using nsgmls.exe validating the file saved above with the dtd .I am getting an error "Character Data Not Allowed Here"
Earlier the code used to save the file is as below

Dim l_oReader As New MSXML2.SAXXMLReader60
Dim l_oWriter As New MSXML2.MXXMLWriter60
Dim l_oStream As New ADODB.Stream

l_oReader.contentHandler = l_oWriter
l_oWriter.byteOrderMark = False
l_oWriter.encoding = p_sEncoding
l_oWriter.omitXMLDeclaration = True
l_oWriter.indent = True
l_oStream.Open()
l_oStream.Charset = p_sEncoding
l_oWriter.output = l_oStream
l_oReader.parse(p_sMessage)
l_oWriter.flush()
l_oStream.SaveToFile(g_sTempProcessFolder & p_sFileName,   ADODB.SaveOptionsEnum.adSaveCreateOverWrite)



使用上述方法使用UTF-8保存文件然后我没有收到任何错误使用nsgmls.exe解析时



我尝试过:



我可以在google上找到关于nsgmls.exe的所有documnet


using the above way to save the file using UTF-8 then I didn't get any errors while parsing using nsgmls.exe

What I have tried:

all the documnets i could find on the google regarding nsgmls.exe

推荐答案

您可以比较生成的文件来自所有使用文本编辑器查看区别的方法( nsgmls 消息应该给你行号)。



一点是您正在调用 StartDocument()但不是 EndDocument()



可能的错误源可能是传递的 p_sMessage 字符串,因为您使用的是XmlWriter.WriteRaw方法(字符串)(System.Xml) [ ^ ]:

You may compare the generated files from all methods using a text editor to see what is the difference (the nsgmls message should give you the line number).

One point is that you are calling StartDocument() but not EndDocument().

A probable error source may be the passed p_sMessage string because you are using XmlWriter.WriteRaw Method (String) (System.Xml)[^]:
Quote:

XmlWriter不验证传递给WriteRaw方法的数据。您不应将任意数据传递给此方法。

The XmlWriter does not validate the data that is passed to the WriteRaw method. You should not pass arbitrary data to this method.


这篇关于为什么nsgmls解析器为utf-8编码文件提供错误“此处不允许使用字符数据”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆