Burada bir powershell işlevi Yorum bir xml düğümü için:
function UncommentXmlNode([String] $filePath, [String] $searchCriteria)
{
[xml]$xml = Get-Content -Path "$filePath"
# Find all comments on the xml file
$xml.SelectNodes("//comment()") | ForEach-Object {
# We convert the comment to an xml
$nodeToConvert = $_;
$convertedNode = $nodeToConvert.InnerText | convertto-xml
[xml]$xmlConvertedNode = $convertedNode
# Find the comment that match our search criteria
$xmlConvertedNode.SelectNodes("/descendant::*[contains(text(), '$searchCriteria')]") | ForEach-Object {
$nodeToUncomment = $_;
$strToFind = "<!--" + $nodeToUncomment.InnerText + "-->"
$strReplacement = $nodeToUncomment.InnerText
# Replace the commented string with uncommented one
$con = Get-Content "$filePath"
$con | % { $_.Replace($strToFind, $strReplacement) } | Set-Content "$filePath"
}
}
}
Böyle kullanabilirsiniz:
İşte
function CommentXmlNode([String] $filePath, [String] $nodeXPath)
{
[xml]$xml = Get-Content -Path "$filePath"
# Find the nodes that we want to comment
$xml.SelectNodes("$nodeXPath") | ForEach-Object {
$nodeToComment = $_;
$comment = $xml.CreateComment($nodeToComment.OuterXml);
# Comment the node
$nodeToComment.ParentNode.ReplaceChild($comment, $nodeToComment);
}
# Save the file
$xml.Save("$filePath");
}
Uncomment xml düğüm bir powershell fonksiyonudur
CommentXmlNode "D:\temp\file.xml" "YourXPath"
-
UncommentXmlNode "D:\temp\file.xml" "Some String in the xml node to Uncomment"
Biçimlendirmesini korumak istiyor ve yorumların etiketi içermez yorumladı Düğüm Değerini içeren bir geçici düğümünü inşa dize değiştirme
kullanmıyorsanız
Her dilde bir şeyler yorumlama yolu vardır. Powershell'de '# ', C'de' // 've [XML'in kendi yolu vardır] (http://www.w3schools.com/xml/xml_syntax.asp) - aşağıya bakınız. Her yerde (en çok hangisi iseniz) '// 'veya' # 'olduğunu düşünmeyin. – Neolisk