Remove a node from XML file in MS Project VBA [closed]

巧了我就是萌 提交于 2019-12-02 13:14:19

Do you know about XPath? From the painful looks of your code, you do not. Instead of using a long combination of barbaric DOM methods to access the node you need, you should save yourself a lot of pain and just use an XPath to access it in one line.

If I understand correctly what you're trying to do, then something like the following can replace your entire double loop, from i=0 to Next ProjectFileList:

For i = LBound(ProjFiles) To UBound(ProjFiles)
    Set deleteMe = XML.selectSingleNode( _
        "/config/ProjectFile[@ProjectFileName='" & ProjFiles(i) & "']")
    Set oldChild = deleteMe.parentNode.removeChild(deleteMe)
Next i

where the thing in "quotes" is an XPath. Hope this helps.

As a side note, it seems inefficient, confusing, and error-prone to have a ProjectFileName attribute and a FileName element containing the exact same information in your XML file. What's up with that?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!