parseing xml and outputing it ?

Hi All I am trying to parse a series of xml files and pull out the {$_.LayoutElement.name} and {$_.LayoutElement.hyperlinkTemplate.urlTemplate}

however the code below only prints out the last entered xml leaf IE {$_.LayoutElement.hyperlinkTemplate.urlTemplate}

if I delete {$_.LayoutElement.hyperlinkTemplate.urlTemplate} then {$_.LayoutElement.name}  prints out 

Ideally I would be able output a CSV of this data any suggestions?

[xml]$dashboard = Get-Content C:\Users\sas005\Documents\Dashboards\Arts_And_Science-ASDA-9500.dcx
$dashboard.DashboardConfig.RootLayoutElement.LayoutElement.Children | % {$_.LayoutElement.name} {$_.LayoutElement.hyperlinkTemplate.urlTemplate}

September 10th, 2015 4:30pm

You have to post an example of the xml.  We cannot guess at that.

Free Windows Admin Tool Kit Click here and download it now
September 10th, 2015 6:15pm

https://gallery.technet.microsoft.com/PowerShell-Deployment-f20bb605 contains a script that parses a pretty complex xml file.  It is a lot of code with lots of xml examples.  I learned a lot about parsing xml by reading that code and testing out sections in my code.
September 10th, 2015 6:20pm

sure here is the section in question 

I know the code is finding the xmlelements ok because it outputs them just not together so my issue is occuring in the pipe to output 

| % {$_.LayoutElement.name} {$_.LayoutElement.hyperlinkTemplate.urlTemplate}

<LayoutElement name="STDA-9500"
                    type="sas.bid.decorations.staticImage"
                    hidden="false" width="1200" height="650" x="0" y="0"
                    scaleFactor="0.0" foldout="false"
                    zoomXOverride="1.0" zoomYOverride="1.0">
                    <extendedAttributes>
                        <ExtendedAttribute>
                            <type>String</type>
                            <value>http://www.usask.ca/isa/images/Common/Student_reports_background_new.jpg</value>
                            <name>Image URL</name>
                            <description>Image URL</description>
                            <localized-text-bundle>
                                <LocalizedTextLists>
                                    <LocalizedTextList language="en" country="US">
                                    <LocalizedTexts>
                                    <LocalizedText id="name">
                                    <text>Image URL</text>
                                    </LocalizedText>
                                    <LocalizedText id="description">
                                    <text>Image URL</text>
                                    </LocalizedText>
                                    </LocalizedTexts>
                                    </LocalizedTextList>
                                </LocalizedTextLists>
                            </localized-text-bundle>
                            <id>imageUrl</id>
                        </ExtendedAttribute>
                        <ExtendedAttribute>
                            <type>Boolean</type>
                            <value>true</value>
                            <name>Use proxy</name>
                            <description>Use a proxy servlet to retrieve the URL.  If not checked, the webserver containing the image must be in the same network domain as the Dashboard install.</description>
                            <localized-text-bundle>
                                <LocalizedTextLists>
                                    <LocalizedTextList language="en" country="US">
                                    <LocalizedTexts>
                                    <LocalizedText id="name">
                                    <text>Use proxy</text>
                                    </LocalizedText>
                                    <LocalizedText id="description">
                                    <text>Use a proxy servlet to retrieve the URL.  If not checked, the webserver containing the image must be in the same network domain as the Dashboard install.</text>
                                    </LocalizedText>
                                    </LocalizedTexts>
                                    </LocalizedTextList>
                                </LocalizedTextLists>
                            </localized-text-bundle>
                            <id>useProxy</id>
                        </ExtendedAttribute>
                        <ExtendedAttribute>
                            <type>extended_attr.Boolean</type>
                            <value>false</value>
                            <name>Show in a tile</name>
                            <description>Show in a tile</description>
                            <localized-text-bundle>
                                <LocalizedTextLists>
                                    <LocalizedTextList language="en" country="US">
                                    <LocalizedTexts>
                                    <LocalizedText id="name">
                                    <text>Show in a tile</text>
                                    </LocalizedText>
                                    <LocalizedText id="description">
                                    <text>Show in a tile</text>
                                    </LocalizedText>
                                    </LocalizedTexts>
                                    </LocalizedTextList>
                                </LocalizedTextLists>
                            </localized-text-bundle>
                            <id>displayInPanel</id>
                        </ExtendedAttribute>
                    </extendedAttributes>
                    <hyperlinkTemplate
                        urlTemplate="SBIP://METASERVER/Student/Institution Reports/STIR-1202 Enrolment 4 Year Trend by Term and College.srx(Report)"
                        linkTarget="_blank" linkType="Report"
                        linkDisplayName="STIR-1202 Enrolment 4 Year Trend by Term and College.srx"

                        windowWidth="0" windowHeight="0"/>
                </LayoutElement>

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 4:16pm

That is not XML it is a picture copied from IE.  We need the plain  text.  Open the file in notepad and paste it.
September 11th, 2015 4:21pm

This is part of your paste:

<LayoutElement name="STDA-9500"
                     type="sas.bid.decorations.staticImage"
                     hidden="false" width="1200" height="650" x="0" y="0"
                     scaleFactor="0.0" foldout="false"
                     zoomXOverride="1.0" zoomYOverride="1.0">
                     <extendedAttributes>
                         <ExtendedAttribute>
                             <type>String</type>
                             <value>http://www.usask.ca/isa/images/Common/Student_reports_background_new.jpg</value>
                             <name>Image URL</name>
                             <description>Image URL</description>
                             <localized-text-bundle>
                                 <LocalizedTextLists>
                                     <LocalizedTextList language="en" country="US">
                                     <LocalizedTexts>
                                     <LocalizedText id="name">
                                     <text>Image URL</text>
                                     </LocalizedText>
                                     <LocalizedText id="description">
                                     <text>Image URL</text>
                                     </LocalizedText>
                                     </LocalizedTexts>
                                     </LocalizedTextList>
                                 </LocalizedTextLists>
                             </localized-text-bundle>
                             <id>imageUrl</id>
                         </ExtendedAttribute>
                         <ExtendedAttribute>
                             <type>Boolean</type>
                             <value>true</value>
                             <name>Use proxy</name>
                             <description>Use a proxy servlet to retrieve the URL.  If not checked, the webserver containing the image must be in the same network domain as the Dashboard install.</description>
                             <localized-text-bundle>
                                 <LocalizedTextLists>
                                     <LocalizedTextList language="en" country="US">
                                     <LocalizedTexts>
                                     <LocalizedText id="name">
                                     <text>Use proxy</text>
                                     </LocalizedText>
                                     <LocalizedText id="description">
                                     <text>Use a proxy servlet to retrieve the URL.  If not checked, the webserver containing the image must be in the same network domain as the Dashboard install.</text>
                                     </LocalizedText>
                                     </LocalizedTexts>
                                     </LocalizedTextList>
                                 </LocalizedTextLists>
                             </localized-text-bundle>
                             <id>useProxy</id>
                         </ExtendedAttribute>
                         <ExtendedAttribute>
                             <type>extended_attr.Boolean</type>
                             <value>false</value>
                             <name>Show in a tile</name>
                             <description>Show in a tile</description>
                             <localized-text-bundle>
                                 <LocalizedTextLists>
                                     <LocalizedTextList language="en" country="US">
                                     <LocalizedTexts>
                                     <LocalizedText id="name">
                                     <text>Show in a tile</text>
                                     </LocalizedText>
                                     <LocalizedText id="description">
                                     <text>Show in a tile</text>
                                     </LocalizedText>
                                     </LocalizedTexts>
                                     </LocalizedTextList>
                                 </LocalizedTextLists>
                             </localized-text-bundle>
                             <id>displayInPanel</id>
                         </ExtendedAttribute>
                     </extendedAttributes>
                     <hyperlinkTemplate
                         urlTemplate="SBIP://METASERVER/Student/Institution Reports/STIR-1202 Enrolment 4 Year Trend by Term and College.srx(Report)"
                         linkTarget="_blank" linkType="Report"
                         linkDisplayName="STIR-1202 Enrolment 4 Year Trend by Term and College.srx"




                        windowWidth="0" windowHeight="0"/>

Notice how it looks better when posted correctly but it is missing too many pieces and we cannot tell what you are trying to extract.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 4:24pm

Assuming this as the root structure:

$dashboard.DashboardConfig.RootLayoutElement...

Then:

<DashboardConfig>
    <RootLayoutElement>
        <LayoutElement ... >
        <...

And we can do this to get all elements


[xml]$dashboard = Get-Content C:\Users\sas005\Documents\Dashboards\Arts_And_Science-ASDA-9500.dcx
$nodes=$dashboard.SelectNodes('//LayoutElement')

Now we can select a table of interesting attributes.

If you have namespaces in the xml then we need to sue the namespace manager to access the named elements.

September 11th, 2015 4:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics