PowerBuilder MSXML2.DOMDocument.4.0 编码属性不见了
PowerBuilder MSXML2.DOMDocument.4.0 encoding attribute gone
我有一个非常简单的PowerBuilder代码:
OLEObject lole_DOM
lole_DOM = CREATE OLEObject
lole_DOM.ConnectToNewObject("MSXML2.DOMDocument.4.0")
lole_DOM.LoadXML('<?xml version="1.0" encoding="UTF-8"?><root/>')
MessageBox("", String(lole_DOM.XML))
DESTROY lole_DOM
我得到的结果是:
<?xml version="1.0"?>
<root/>
编码属性哪里去了?不知道该怪谁,PowerBuilder 还是 MSXML2.DOMDocument.4.0,有什么想法吗?
使用 PowerBuilder 版本 11.5.1 Build 5097
这是设计使然。如 documentation for the xml
property 的 "Remarks" 部分所述:
The xml
property always returns a Unicode string. That is, the xml
property for DOMDocument
converts the document from its original encoding to Unicode. As a result, the original encoding attribute is removed. For example, <?xml version="1.0" encoding="UTF-8"?>
appears in the xml
property as follows.
<?xml version="1.0"?>
相比之下,如果您将文档保存到文件中 save()
您会看到文件中的处理指令是完整的,并且文件已相应编码。
我有一个非常简单的PowerBuilder代码:
OLEObject lole_DOM
lole_DOM = CREATE OLEObject
lole_DOM.ConnectToNewObject("MSXML2.DOMDocument.4.0")
lole_DOM.LoadXML('<?xml version="1.0" encoding="UTF-8"?><root/>')
MessageBox("", String(lole_DOM.XML))
DESTROY lole_DOM
我得到的结果是:
<?xml version="1.0"?>
<root/>
编码属性哪里去了?不知道该怪谁,PowerBuilder 还是 MSXML2.DOMDocument.4.0,有什么想法吗?
使用 PowerBuilder 版本 11.5.1 Build 5097
这是设计使然。如 documentation for the xml
property 的 "Remarks" 部分所述:
The
xml
property always returns a Unicode string. That is, thexml
property forDOMDocument
converts the document from its original encoding to Unicode. As a result, the original encoding attribute is removed. For example,<?xml version="1.0" encoding="UTF-8"?>
appears in thexml
property as follows.<?xml version="1.0"?>
相比之下,如果您将文档保存到文件中 save()
您会看到文件中的处理指令是完整的,并且文件已相应编码。