以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  讨厌 xmlns="" 属性,请高手帮助  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=27814)


--  作者:ed_yuqing
--  发布时间:2/26/2006 5:52:00 PM

--  讨厌 xmlns="" 属性,请高手帮助

<?xml version="1.0"?>
<?xml-stylesheet type='text/xml' href='test.xsl'?>
<!--sample xml file created using XML DOM object.-->
<root xmlns="urn:schemas-microsoft-com:office:excel">
 <node1 xmlns="">some character data</node1>
</root>

xmlns=""是程序自动生成的,是执行完dom.save App.Path + "\dynamDom.xml"这句后,程序自动加上去的.可我不想要这个(xmlns="")属性,我该如何设置DOMDocument30对象?

以下是我的VB源码:
Private Function CreateDOM()
    Dim dom
    Set dom = New DOMDocument30
    dom.async = False
    dom.validateOnParse = False
    dom.resolveExternals = False
    dom.preserveWhiteSpace = True
    Set CreateDOM = dom
End Function

Private Sub Form_Load()
    Dim dom, node, attr

    On Error GoTo ErrorHandler

    Set dom = CreateDOM
    
    Set node = dom.createProcessingInstruction("xml", "version='1.0'")
    dom.appendChild node
    Set node = Nothing
    
    Set node = dom.createProcessingInstruction("xml-stylesheet", _
                                "type='text/xml' href='test.xsl'")
    dom.appendChild node
    Set node = Nothing
    
    Set node = dom.createComment("sample xml file created using XML DOM object.")
    dom.appendChild node
    Set node = Nothing

    Dim root
    Set root = dom.createElement("root")
    

    Set attr = dom.createAttribute("xmlns")
    attr.Value = "urn:schemas-microsoft-com:office:excel"
    root.setAttributeNode attr
    Set attr = Nothing
    
    dom.appendChild root
    
    root.appendChild dom.createTextNode(vbNewLine + vbTab)

    Set node = dom.createElement("node1")
    node.Text = "some character data"

    root.appendChild node
    Set node = Nothing


    root.appendChild dom.createTextNode(vbNewLine)
    Set node = Nothing
    

    dom.save App.Path + "\dynamDom.xml"
    Set root = Nothing
    Set dom = Nothing
    Exit Sub
    
ErrorHandler:
    MsgBox Err.Description
End Sub


--  作者:ed_yuqing
--  发布时间:2/27/2006 4:50:00 PM

--  问题已经解决
将 Set node = dom.createElement("node1")
改成 Set node = dom.createNode(NODE_ELEMENT, "Node1", "urn:schemas-microsoft-com:office:excel")

一切OK

具体原因,请参看微软的Knowledge Base
PRB: DOMDocument.CreateNode() Method Appends an Empty Namespace DeclarationPSS ID Number: Q290485


--  作者:zjsbyh
--  发布时间:5/18/2006 12:35:00 AM

--  
我也遇到了这个问题。请问你有java版的解决方式么?谢谢,我的msn是:sword10000@hotmail.com
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms