I am trying to read XML content from which is stored in a text file. But it is not working properly. Please go through my code as mention below:
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
In line no 3 of the above code I am trying to read XML content from the text file. If I remove [xml] then Get-Content is working fine. But need that content in XML format. Can anyone help me to overcome this issue?
This is the content of my file content
<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>
Thank you in Advance
CodePudding user response:
The following works here:
[xml] $x = gc infile.xml
$x.Envelope.Body.uploadFileToUcm.document.content='Hello World'
$x.save("$((pwd).path)\outfile.xml")
gc outfile.xml
Output:
<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>
CodePudding user response:
assuming the file is well formatted as xml, I would create a new instance of a xml object and use the load method:
$path='D:\SOAP\PozEncoXML.txt'
$xml = New-Object -TypeName xml
$xml.Load($path)
[System.Xml.Linq.XDocument]::Parse($Xml.OuterXml).ToString()
Output
<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>