我正在嘗試讀取存盤在文本檔案中的 XML 內容。但它不能正常作業。請仔細閱讀我的代碼,如下所述:
Write-Host 'Welcome'
$path='D:\SOAP\PozEncoXML.txt'
$xml=[xml](Get-Content -path $path)
Write-Host 'File Content'
write-host $xml
$node= $xml.Envelope.Body.uploadFileToUcm.document.Content='Hello world'
Write-Host $node
在上述代碼的第 3 行中,我試圖從文本檔案中讀取 XML 內容。如果我洗掉 [xml] 那么 Get-Content 作業正常。但需要 XML 格式的內容。誰能幫我克服這個問題?
這是我的檔案內容的內容
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/types/" xmlns:fin="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/">
<soapenv:Header/>
<soapenv:Body>
<typ:uploadFileToUcm>
<typ:document>
<fin:Content></fin:Content>
<fin:FileName>xxxxx.csv</fin:FileName>
<fin:ContentType>csv</fin:ContentType>
<fin:DocumentTitle>Journal Import</fin:DocumentTitle>
<fin:DocumentAuthor>xxxx</fin:DocumentAuthor>
<fin:DocumentSecurityGroup>FAFusionImportExport</fin:DocumentSecurityGroup>
<fin:DocumentAccount>fin$/generalLedger$/import$</fin:DocumentAccount>
<fin:DocumentName>?</fin:DocumentName>
<fin:DocumentId>?</fin:DocumentId>
</typ:document>
</typ:uploadFileToUcm>
</soapenv:Body>
</soapenv:Envelope>
先感謝您
uj5u.com熱心網友回復:
以下作業在這里:
[xml] $x = gc infile.xml
$x.Envelope.Body.uploadFileToUcm.document.content='Hello World'
$x.save("$((pwd).path)\outfile.xml")
gc outfile.xml
輸出:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/types/" xmlns:fin="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/">
<soapenv:Header />
<soapenv:Body>
<typ:uploadFileToUcm>
<typ:document>
<fin:Content>Hello World</fin:Content>
<fin:FileName>xxxxx.csv</fin:FileName>
<fin:ContentType>csv</fin:ContentType>
<fin:DocumentTitle>Journal Import</fin:DocumentTitle>
<fin:DocumentAuthor>xxxx</fin:DocumentAuthor>
<fin:DocumentSecurityGroup>FAFusionImportExport</fin:DocumentSecurityGroup>
<fin:DocumentAccount>fin$/generalLedger$/import$</fin:DocumentAccount>
<fin:DocumentName>?</fin:DocumentName>
<fin:DocumentId>?</fin:DocumentId>
</typ:document>
</typ:uploadFileToUcm>
</soapenv:Body>
</soapenv:Envelope>
uj5u.com熱心網友回復:
假設檔案格式正確為 xml,我將創建一個 xml 物件的新實體并使用 load 方法:
$path='D:\SOAP\PozEncoXML.txt'
$xml = New-Object -TypeName xml
$xml.Load($path)
[System.Xml.Linq.XDocument]::Parse($Xml.OuterXml).ToString()
輸出
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/types/" xmlns:fin="http://xmlns.oracle.com/apps/financials/commonModules/shared/financialUtilService/">
<soapenv:Header />
<soapenv:Body>
<typ:uploadFileToUcm>
<typ:document>
<fin:Content>Hello world</fin:Content>
<fin:FileName>xxxxx.csv</fin:FileName>
<fin:ContentType>csv</fin:ContentType>
<fin:DocumentTitle>Journal Import</fin:DocumentTitle>
<fin:DocumentAuthor>xxxx</fin:DocumentAuthor>
<fin:DocumentSecurityGroup>FAFusionImportExport</fin:DocumentSecurityGroup>
<fin:DocumentAccount>fin$/generalLedger$/import$</fin:DocumentAccount>
<fin:DocumentName>?</fin:DocumentName>
<fin:DocumentId>?</fin:DocumentId>
</typ:document>
</typ:uploadFileToUcm>
</soapenv:Body>
</soapenv:Envelope>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/508611.html