我有一個小問題。現在我有以下代碼:
$xmlFile = 'C:UsersjonbDesktopom.xml' 。
[xml]$xml = Get-Content $xmlFile
$xml.bom.component.component | ForEach-Object {
$finalObject = [PSCustomObject]@{
'名稱' = $_.名稱
'版本' = $_.版本
'許可證' = $_.licenses.license.id
}
Write-Output $finalObject
}
我也有以下的xml檔案:
<bom xmlns="http://cyclonedx.org/schema/bom/1. 2" serialNumber="urn:uuid: 7994040c-b12e-4d3d-96a2-b2112e725d0b" version="1">
<metadata>/span>
<timestamp>2021-08-25T23:47:51.782Z</timestamp>/span>
<tools>/span>
<tool>/span>
<vendor>CycloneDX</vendor>
<name>Node.js模塊</name>/span>
<version>2.0.0</version>/span>
</tool>/span>
</tools>/span>
</metadata>/span>
<components>/span>
< component type="library" bom-ref="pkg:npm/@mdi/[email protected]"> >。
<group>/span>@mdi</group>/span>
<name>/span>font</name>/span>
<version>/span>4.9.95</version>/span>
<description>/span>
<![CDATA[Dist for Material Design Webfont。這包括在一個網頁字體集合中的庫存和社區圖示。]]>
</description>
<hash>
<hash alg="SHA-512"/span>> 9b6b1b02cf923304675a990cae207112e970ba19aa47287a5fe85d39996a4b161950cd82d936839d0e20722973768020aeed97627595899ff13ee4831a045757< /hash>。
</hash>/span>
<purl>pkg:npm/@mdi/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://materialdesignicons.com</url>
</reference>/span>
<reference type="issue-tracker"/span>>
<url>https://github.com/Templarian/MaterialDesign/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/Templarian/MaterialDesign-Webfont.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/@storybook/[email protected]">/span>
<group>/span>@storybook</group>
<name>/span>addon-a11y</name>/span>
<version>/span>6.2.9</version>/span>
<description>/span>
<![CDATA[ 測驗組件是否符合網路可訪問性標準]]>。
</description>
<hash>
<hash alg="SHA-512"/span>> c28ee716912a11e8870ec44a9e1a9eda020767d67bfc079fc39ef4901811794e6d2a59ab6f9ac501f4d50561816652c759e24cb05b11b16ad6ae691fd41e7639< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/@storybook/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/storybookjs/storybook#readme</url>
</reference>/span>
<reference type="issue-tracker">
<url>https://github.com/storybookjs/storybook/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/storybookjs/storybook.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/@storybook/[email protected]">/span>
<group>/span>@storybook</group>
<name>/span>addons</name>/span>
<version>/span>6.2.9</version>/span>
<description>/span>
<! [CDATA[ Storybook addons store ]]>
</description>
<hash>
<hash alg="SHA-512"/span>> 1a798429b27088dd639dc37d35203c0ae4758b65c095ab0f725fd99f48e47d5f568ad41e73355c2423f0f3a4861fce000feb53042c85da2f540b429a395d5805< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/@storybook/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/storybookjs/storybook/tree/master/lib/addons</url>
</reference>/span>
<reference type="issue-tracker">
<url>https://github.com/storybookjs/storybook/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/storybookjs/storybook.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/@storybook/[email protected]">/span>
<group>/span>@storybook</group>
<name>/span>api</name>
<version>/span>6.2.9</version>
<description>/span>
<! [CDATA[ Core Storybook API & Context ]]>
</description>
<hash>
<hash alg="SHA-512"/span>> a24900dc7012704f6d1a7601ae34ce720cd3f8bd65447368121dd97c6821d6efd7344c8718d923e20aef91dea75fb07345c610fe5d9591c282aa63a35274a455< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/@storybook/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/storybookjs/storybook/tree/master/lib/api</url>
</reference>/span>
<reference type="issue-tracker">
<url>https://github.com/storybookjs/storybook/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/storybookjs/storybook.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/@reach/[email protected]"> >。
<group>/span>@reach</group>/span>
<name>/span>router</name>
<version>/span>1.3.4</version>/span>
<description>/span>
<! [CDATA[ Next generation Routing for React. ]]>
</description>
<hash>
<hash alg="SHA-512"/span>> fa6b67f708e507d34dd823679c2fc1458b7074a05f4b2c9ab0f62b68d032bda575a1c72bff9367078095ce31198a9347c1879b430727746526a45cf1014a2a48< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/@reach/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/reach/router#readme</url>
</reference>/span>
<reference type="issue-tracker">
<url>https://github.com/reach/router/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/reach/router.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/[email protected]"> >。
<name>create-react-context</name>
<version>/span>0.3.0</version>/span>
<description>/span>
<! [CDATA[ Polyfill for the proposed React context API ]] >
</description>
<hash>
<hash alg="SHA-512"/span>> 74d95d2284ae352be54c9eec948282fd914629ec41301aeb71cf934ded4d76644e9da012b8b3efaa9c23f6fe174b8b9767cf983eed2c3664a15f6ad72392cdb3< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/thejameskyle/create-react-context#readme</url>
</reference>/span>
<reference type="issue-tracker"/span>>
<url>https://github.com/thejameskyle/create-react-context/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/thejameskyle/create-react-context.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/[email protected]"> >。
<name>古德</name>
<version>/span>1.0.0</version>/span>
<description>/span>
<![CDATA[ 創建一個'gud nuff'(不是加密安全的)全球唯一ID]]>。
</description>
<hash>
<hash alg="SHA-512"/span>> cc610e54a14ce6c54f3eb62cec9e7f858130d8fa1ff0a0b23b0ca11bcb00176ea60807941407183eed66c01ee186920fdbdcce201683ab0b8774ba748ef6578f< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/jamiebuilds/global-unique-id#readme</url>
</reference>/span>
<reference type="issue-tracker"/span>>
<url>https://github.com/jamiebuilds/global-unique-id/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/jamiebuilds/global-unique-id.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/[email protected]"> >。
<name>warning</name>/span>
<version>/span>4.0.3</version>/span>
<description>/span>
<![CDATA[ Facebook警告的鏡像]]>。
</description>
<hash>
<hash alg="SHA-512"/span>> ae9272376db629622f1c9fc5e775d266fd1997f69c72a1d1f1eb7592968c4c3fdf2c2471b55f225fc73333363bb1566ea53237cdc51383c7b2712da4345f65eb< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/BerkeleyTrue/warning</url>
</reference>/span>
<reference type="issue-tracker"/span>>
<url>https://github.com/BerkeleyTrue/warning/issues</url>
</reference>/span>
<reference type="vcs">
<url>git https://github.com/BerkeleyTrue/warning.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
< component type="library" bom-ref="pkg:npm/[email protected]">/span>
<name>/span>loose-envify</name>/span>
<version>/span>1.4.0</version>/span>
<description>/span>
<![CDATA[快速(和松散)的選擇性`process.env`替換器使用js-tokens而不是AST]]>。
</description>
<hash>
<hash alg="SHA-512"/span>> 972bb13c6aff59f86b95e9b608bfd472751cd7372a280226043cee918ed8e45ff242235d928ebe7d12debe5c351e03324b0edfeb5d54218e34f04b71452a0add< /hash>。
</hash>/span>
<licenses>/span>
<license>/span>
<id>/span>MIT</id>/span>
</license>/span>
</licenses>/span>
<purl>pkg:npm/[email protected]</purl>/span>
<externalReferences>
<reference type="site">/span>
<url>https://github.com/zertosh/loose-envify</url>
</reference>/span>
<reference type="issue-tracker"/span>>
<url>https://github.com/zertosh/loose-envify/issues</url>
</reference>/span>
<reference type="vcs">
<url>git://github.com/zertosh/loose-envify.git</url>
</reference>/span>
</externalReferences>/span>
</component>/span>
這就是我的輸出:
名稱 版本 許可
---- ------- -------
字體 4.9.95
addon-a11y 6.2.9 MIT
addons 6.2.9 MIT
api 6.2.9 MIT
路由器 1.3.4 MIT
create-react-context 0.3.0 MIT
gud 1.0.0 MIT
警告 4.0.3 MIT
loose-envify 1.4.0 MIT
我現在有兩個問題。不是我所有的組件都有許可證。我現在想為那些沒有許可證的組件寫上 "No License"。 我必須做這樣的事情。
$license = $(if ($lic_cond) {$lic_cond} else {"No license"})
不幸的是,我的解決方案還不能完全奏效。
我的第二個問題是,我還想輸出參考。 我可以很簡單地用這么做:
$xml.bom.component.component | ForEach-Object {
[PSCustomObject]@{
'名稱' = $_.名稱
'版本' = $_.版本
'許可證' = $_.licenses.license.id
'網站' = $_.externalReferences.reference.url
}
}
}
現在,它在邏輯上向我輸出了所有的參考。然而,我只想獲得type="site "的參考。
在進一步的步驟中,我希望將參考與名稱聯系起來。這樣,當你點擊這個名字時,它就會把你帶到相應的網站。我問了谷歌。在這里我只找到了這個:
New-Item -ItemType Junction -Path "C:LINK" -Target "C:SOURCE".
然而,這很可能不是一個好辦法。
有什么方法可以解決這個問題嗎?
謝謝你的幫助。
謝謝你的幫助。
|Name|Version|License|Website||
|----|-------|-------|-------|
|@mdi/font|4.9.95|無許可證|[TheNameForTheUrl](https://materialdesignicons.com)|
|@storybook/addon-a11y|6.2.9|MIT|[TheNameForTheUrl](https://github.com/storybookjs/storybook#readme)|
|@storybook/addons|6.2.9|MIT|[TheNameForTheUrl](https://github.com/storybookjs/storybook/tree/master/lib/addons)|
|@storybook/api|6.2.9|MIT|[TheNameForTheUrl](https://github.com/storybookjs/storybook/tree/master/lib/api)|
|@reach/router|1.3.4|MIT|[TheNameForTheUrl](https://github.com/reach/router#readme)|
uj5u.com熱心網友回復:
你的XML例子缺少最后兩個關閉標簽。
就像你的前一個問題一樣,你可以使用這個:
function ConvertTo-MarkDownTable {
[CmdletBinding()] param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]。
$InputObject
)
開始 {
$headersDone = $false
$pattern = '(?<!)|' # 轉義每個'|',除非已經轉義了
}
處理 {
如果(!$headersDone) {
$headersDone = $true
# 輸出標題行和下面的虛線
# -替換'(?<!)|', '|'會轉義每個'|',除非已經轉義了
'|{0}|' -f (($_.PSObject.Properties.Name -replace $pattern, '|') -join '|' )
'|{0}|' -f (($_.PSObject.Properties.Name -replace '.', '-') -join '|')
}
'|{0}|' -f (($_.PsObject.Properties.Value -replace $pattern, '|') -join '|')
}
}
$finalObject = $xml.bom.component.component | ForEach-Object {
$lic = $_.licenses.license.id
$web = ($_.externalReferences.reference | Where-Object { $_.type -eq 'website' }).url
[PSCustomObject]@{
'名稱' = $_.名稱
'版本' = $_.版本
'許可證' = if ([string]::IsNullOrWhiteSpace($lic)){'無許可證' } else {$lic}
'網站' = if ($web) { '[{0}]({0})' -f $web }
}
}
# 轉換為markdown
$finalObject | ConvertTo-MarkDownTable
輸出:
| 名稱 | 版本 | 許可Website | 字體 | 4.9.95|||
|---|---|---|---|---|---|---|
| 沒有許可證 | ||||||
| 沒有許可證 | https://materialdesignicons.com | 。addon-a11y | 6.2.9 | MIT | 6.2.9 | MIT | https://github.com/storybookjs/storybook#readme。addons | 6.2.9 | MIT | https://github.com/storybookjs/storybook/tree/master/lib/addons | 。api | 6.2.9 | MIT | https://github.com/storybookjs/storybook/tree/master/lib/api | 。路由器 | 1.3.4MIT | https://github.com/reach/router#readme | 。創建反應-背景關系 |
| 創建反應-背景關系 | 創建反應-背景關系 | 0.3.0 | MIT | https://github.com/thejameskyle/create-react-context#readme。gud | 1.0.0 | MIT | https://github.com/jamiebuilds/global-unique-id#readme | 。警告 | 4.0.3MIT | https://github.com/BerkeleyTrue/warning。1.4.0 | MIT | https://github.com/zertosh/loose-envify。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/312714.html
標籤:
上一篇:在C#中計算100分之一的秒數
