I've got a script that checks XML files for errors. One thing that it does is to make sure that there is an attachment file name present. I finally figured out how to make it perform as expected, but I was hoping that someone could help me to understand what I was doing wrong.
In essence, the pertinent XML structure is like so:
Occasionally, I need to process old files that are slightly different (no pagecount attribute):
Using this:
$xmlFilename_Attachment = [string]$xd.DocumentElement.filename_attachment.InnerText
Old XML returned nothing
New XML returned "408901.pdf"
If I cut off ".InnerText"
Old XML returned "370000.pdf"
New XML returned "System.Xml.XmlElement"
I finally settled on using this:
It seems to work on either version of my XML files.
I'd like to have a better understanding as to why the inclusion/exclusion of ".InnerText" and the "pagecount" attribute screwed things up. Also, I'd like to know if there is a better way to get the file name information.
In essence, the pertinent XML structure is like so:
Code:
<Invoice>
<filename_attachment pagecount="1">408901.pdf</filename_attachment>
</Invoice>
Code:
<Invoice>
<filename_attachment>370000.pdf</filename_attachment>
</Invoice>
Using this:
$xmlFilename_Attachment = [string]$xd.DocumentElement.filename_attachment.InnerText
Old XML returned nothing
New XML returned "408901.pdf"
If I cut off ".InnerText"
Old XML returned "370000.pdf"
New XML returned "System.Xml.XmlElement"
I finally settled on using this:
Code:
$xmlFilename_Attachment = $xd.get_DocumentElement().GetElementsByTagName("filename_attachment").Item(0).InnerText
I'd like to have a better understanding as to why the inclusion/exclusion of ".InnerText" and the "pagecount" attribute screwed things up. Also, I'd like to know if there is a better way to get the file name information.