2015-05-12 77 views
0

假设的Atom feed的XML:显示元素的属性

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<feed ... > 
    <title type="text">Attachments</title> 
    <id>http://server/list/_vti_bin/listdata.svc/list(1234)/Attachments/</id> 
    <updated>2015-05-12T13:00:05Z</updated> 
    <link rel="self" title="Attachments" href="Attachments" /> 
    <entry> 
    <id>...</id> 
    <title type="text">spreadsheet.xlsx</title> 
    <updated>2015-05-12T13:00:05Z</updated> 
    <author> 
     <name /> 
    </author> 
    <link ... /> 
    <link ... /> 
    <category term="Microsoft.SharePoint.DataService.AttachmentsItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
    <content type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" src="http://server/list/Attachments/1234/spreadsheet.xlsx" /> 
    <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"> 
     <d:EntitySet>TheList</d:EntitySet> 
     <d:ItemId m:type="Edm.Int32">1234</d:ItemId> 
     <d:Name>spreadsheet.xlsx</d:Name> 
    </m:properties> 
    </entry> 

不幸的是,$_.Content.'#type'$_.Content.'#src'不识别的属性:

$webRequest = Invoke-WebRequest -Uri $url -Method Get -UseDefaultCredentials 
[xml]$xml = $webRequest.Content 

$properties = $xml.feed.entry 
$properties | Format-Table -Property ` 
    @{Label="Title"; Expression={$_.Title.'#text'}; Width=50}, 
    @{Label="Url"; Expression={$_.Content.'#src'}; Width=20}, 
    @{Label="ContentType"; Expression={$_.Content.'#type'}; Width=12} 

什么是正确的语法来获得与content.typecontent.src属性关联的内容?

回答

0

你不必使用标签。

PS>$xml.feed.entry.content.type          
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 
相关问题