parsing problem with xml definitions

powershell find value of a xml tag in the attached xml

I want to find the COEStatusCode (in this case its unknown)

I tried $xmldata = [xml] (Get-Content https-photos.xml)
and then $xmldata.Objs.Version.COEStatuscode but it doesnt look like I am doing the right thing.

I'd like to know how to parse such xmls.

Thank You!
https-photos.xml
DevSupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rastoiWindows DTS expertCommented:
probably due to invalid xml format. tha t "version" inside <XD> field cancels further interpreting.
there no correct xml structure inside and whole part between <XD> and </XD> is represented like one string
0
rastoiWindows DTS expertCommented:
I played a bit with and this transformation makes the trick

[xml]$a =get-content C:\https-photos.xml 
$a.Objs.xd=$a.Objs.xd.Replace("?","")
$a.Objs.xd=$a.Objs.xd+"</xml>"
[xml]$b=$a.Objs.xd
$b.xml.Envelope.body.PhotoList

Open in new window


with output:

ns1                  : Output:EBSHRIS:Timesheet:List
COEStatusCode        : UNKNOWNERROR
 COEStatusDescription : the HTTP response code of 500 indicated a server error. The response data may contain a reason.
ResultCount          :
ResultList           :

so you can query then $b.xml.Envelope.body.PhotoList.COEStatuscode directly
0
oBdACommented:
No need for character based editing here. That is valid xml, and it's just an exported/serialized xml PowerShell variable.
So all you need to do is import the file, and you can access the real xml directly:
$xml = Import-Clixml -Path C:\Temp\https-photos.xml
$COEStatusCode = $xml.Envelope.Body.PhotoList.COEStatusCode

Open in new window


Once imported back into PS, the xml looks like that, btw:
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<ns1:PhotoList xmlns:ns1="Output:EBSHRIS:Timesheet:List">
			<COEStatusCode>UNKNOWNERROR</COEStatusCode>
			<COEStatusDescription>the HTTP response code of 500 indicated a server error. The response data may contain a reason.</COEStatusDescription>
			<ResultCount></ResultCount>
			<ResultList></ResultList>
		</ns1:PhotoList>
	</soap:Body>
</soap:Envelope>

Open in new window

2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DevSupportAuthor Commented:
Thank You so much!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.