无法删除默认的xml命名空间属性?

时间:2016-02-06 17:33:49

标签: xml vba msxml

为什么我无法删除所有命名空间属性?

<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 
    http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" 
    xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1" 
    xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1" 
    xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" 
    xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" 
    xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
Sub insStyleS(xmlFil As String)
Dim xmlDoc As MSXML2.DOMDocument60
Dim stylePI As MSXML2.IXMLDOMProcessingInstruction
Dim xNodeList As MSXML2.IXMLDOMNodeList
Dim xNode As MSXML2.IXMLDOMNode
Dim xAtt As MSXML2.IXMLDOMAttribute
Dim tabort1, tabort2 As String

Set xmlDoc = New DOMDocument60
If Not xmlDoc.Load(xmlFil) Then
    Err.Raise xmlDoc.parseError.ErrorCode, , xmlDoc.parseError.reason
End If
Set xNodeList = xmlDoc.ChildNodes
For Each xNode In xNodeList
    If xNode.BaseName = "TrainingCenterDatabase" Then
'*****
        For Each xAtt In xNode.Attributes
            tabort1 = CStr(xAtt.Name)
            tabort2 = CStr(xAtt.NamespaceURI)
'            xNode.Attributes.removeNamedItem tabort1
            xNode.Attributes.removeQualifiedItem tabort1, tabort2
        Next xAtt
'*****
    End If
    If xNode.BaseName = "xml-stylesheet" Then
        xNode.ParentNode.RemoveChild xNode
    End If
Next xNode
Set stylePI = xmlDoc.createProcessingInstruction("xml-stylesheet", _
    "type=""text/xsl"" href=""wahoo_TCX.xsl""")
xmlDoc.InsertBefore stylePI, xmlDoc.ChildNodes.Item(1)
xmlDoc.Save xmlFil
Set xmlDoc = Nothing
End Sub`

Name和NamespaceURI产生这个:

xsi:schemaLocation  http://www.w3.org/2001/XMLSchema-instance
xmlns:ns5   http://www.w3.org/2000/xmlns/
xmlns:ns4   http://www.w3.org/2000/xmlns/
xmlns:ns3   http://www.w3.org/2000/xmlns/
xmlns:ns2   http://www.w3.org/2000/xmlns/
xmlns   http://www.w3.org/2000/xmlns/
xmlns:xsi   http://www.w3.org/2000/xmlns/

但是没有删除任何东西,'BaseName'和'NamespaceURI'会删除所有带前缀的内容,但不删除'xmlns'默认'NameSpace'。使用Name和'removeNamedItem'它也是一样的。 是否不允许删除默认的“NameSpace”? 如果我只有带前缀的'xmlns',则删除所有内容。 为什么'NamespaceURI'与xml文件中的不同?

0 个答案:

没有答案