2016-12-01 4 views
-1

배치 스크립트를 처음 사용합니다. 특정 파일의 문자열을 대체하려고합니다. 아래 스크립트에서 오류가 발생했습니다.배치 스크립트를 사용하여 XML 파일의 문자열 바꾸기

@echo off 
$standalone = Get-Content 'C:\wildfly\standalone\configuration\standalone.xml' 

$standalone -replace '<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>','<wsdl-host>${jboss.bind.address:0.0.0.0}</wsdl-host>' | 
Set-Content 'C:\wildfly\standalone\configuration\standalone.xml' 
+4

줄 1은 일괄 처리이고 나머지는 PowerShell입니다. –

+0

배치 스크립트로만 작성하려고합니다 – venky

+5

XML 파일을 일괄 편집하지 않으려 고합니다. 날 믿어. –

답변

1

XML을 편집하는 적절한 방법은 문자열이 아닌 XML 문서로 처리하는 것입니다. 이는 XML 파일이 특정 형식을 유지할 수 없기 때문입니다. 모든 편집은 컨텍스트 인식이어야하며 문자열 바꾸기는 그렇지 않습니다. 세 eqvivalent XML 조각을 고려 요소 이름에 whitespacing 것은 다른과 it's legal

<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host> 

<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host > 

<wsdl-host >${jboss.bind.address:127.0.0.1}</wsdl-host > 

참고 일부를 추가 할 수 있습니다. 정말 처리하는 것이 훨씬 이해가되지 않습니다

<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host> 

<wsdl-host>${jboss.bind.address:127.0.0.1} 
</wsdl-host> 

: 무엇보다, 실제로, 다음 단순히 요소 값에 줄 바꿈을 폐기 구현의 많은, 그래서 두 사람은 설정 파서에 동일한 결과를 제공 할 가능성이있다 문자열로 XML을, 그렇지?

다행히 Powershell에는 XML 파일에 대한 지원 기능이 내장되어 있습니다. 간단한 접근 방식은 PowerShell을 사용할 수 없습니다 및 배치 스크립트와 함께 붙어있는 경우, 당신이 정말로 제 3 자 XML 조작 프로그램을 사용할 필요가

# Mock XML config 
[xml]$x = @' 
<root> 
<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host> 
</root> 
'@ 

# Let's change the wsdl-host element's contents 
$x.root.'wsdl-host' = '${jboss.bind.address:0.0.0.0}' 

# Save the modified document to console to see the change 
$x.save([console]::out) 

<?xml version="1.0" encoding="ibm850"?> 
<root> 
    <wsdl-host>${jboss.bind.address:0.0.0.0}</wsdl-host> 
</root> 

, 그래서 같다.

+0

답장을 보내 주셔서 감사합니다. 파일에서 .xml 형식으로 만 해당하는 wildfly도 변경하고 싶습니다. 스크립트에서 파일의 경로를 지정할 수 있습니까? – venky

관련 문제