Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XML文档中合并相邻的SPAN标记?_Xml_Dom_Powershell_Html - Fatal编程技术网

如何在XML文档中合并相邻的SPAN标记?

如何在XML文档中合并相邻的SPAN标记?,xml,dom,powershell,html,Xml,Dom,Powershell,Html,我们有一些XML文档,其中包含一些以位为单位的XHTML。HTML源于MS Word或其他东西,除了内容之外,有许多相邻的SPAN标记完全相同 我一直在将XML加载到powershell中,并比较相邻节点等,但这似乎很费劲,而且很有可能出错。有没有一种聪明的方法可以通过XML DOM或HTML DOM做到这一点?以下是我的想法: function removeNode($mynode){ $parent = $mynode.get_parentNode() $parent.rem

我们有一些XML文档,其中包含一些以位为单位的XHTML。HTML源于MS Word或其他东西,除了内容之外,有许多相邻的SPAN标记完全相同


我一直在将XML加载到powershell中,并比较相邻节点等,但这似乎很费劲,而且很有可能出错。有没有一种聪明的方法可以通过XML DOM或HTML DOM做到这一点?

以下是我的想法:

function removeNode($mynode){
    $parent = $mynode.get_parentNode()
    $parent.removeChild($mynode)
}

function parseStyles($mySpans){
    $global:finished = $true
    foreach($span in $mySpans){
        if($span.('#text') -eq $null -and !$span.haschildnodes){
            removeNode $span
        }
        elseif($span.get_NextSibling() -ne $null){
            if($span.get_NextSibling().style -eq $span.style){
                $span.get_innerText()+$span.get_NextSibling().get_InnerText()
                $span.'#text' = $span.get_innerText()+$span.get_NextSibling().get_InnerText()
                $span.('#text')
                removeNode $span.get_NextSibling()
                $global:finished = $false
            }
        }
    }
    return $mySpans
}
$global:finished = $true
$files = get-childitem -recurse -include "*.xml"

foreach($file in $files){

    [xml]$inputXML = Get-Content($file.directory.name+'\'+$file.name)
    do{
        $Spans = $inputXML.selectnodes('//span')
        parseStyles($Spans)
    }until($global:finished)
    $inputXML.save('./desktop/prometric/'+$file.directory.name+'/processed_'+$file.name)
}

您能展示一些您当前使用的XML和PowerShell代码示例吗?XML看起来像这样:您公司的一些移动销售代表使用运行Microsoft Office Outlook 2007和