0

i have an data.xml with following

<?xml version="1.0" encoding="UTF-8"?>
<animetitles>
    <anime aid="1">
        <title type="short" xml:lang="en">CotS</title>
        <title xml:lang="fr" type="official">Crest of the Stars</title>
        <title type="official" xml:lang="en">Crest of the Stars</title>
        <title xml:lang="pl" type="official">Crest of the Stars</title>
        <title type="syn" xml:lang="cs">Hvězdný erb</title>
        <title type="main" xml:lang="x-jat">Seikai no Monshou</title>
        <title xml:lang="x-jat" type="short">SnM</title>
        <title type="syn" xml:lang="ko">성계의 문장</title>
        <title type="official" xml:lang="ja">星界の紋章</title>
        <title xml:lang="zh-Hans" type="syn">星界之纹章</title>
    </anime>
    <anime aid="2">
        <title type="official" xml:lang="ja">3×3 EYES</title>
        <title type="short" xml:lang="x-jat">3x3</title>
        <title type="official" xml:lang="de">3x3 Augen (OVA 1)</title>
        <title type="main" xml:lang="x-jat">3x3 Eyes</title>
        <title type="official" xml:lang="en">3x3 Eyes</title>
        <title type="official" xml:lang="fr">3x3 Eyes</title>
        <title xml:lang="en" type="syn">3x3 Eyes - Immortals</title>
        <title xml:lang="it" type="official">3x3 Occhi</title>
        <title xml:lang="cs" type="official">3x3 Oči</title>
        <title xml:lang="sv" type="official">3x3 Ögon</title>
        <title type="official" xml:lang="es">3x3 Ojos [1-4]</title>
        <title type="official" xml:lang="ca">3x3 Ulls</title>
        <title xml:lang="ru" type="syn">3x3 глаза</title>
        <title type="syn" xml:lang="x-jat">Sazan Eyes</title>
        <title type="syn" xml:lang="x-jat">Southern Eyes</title>
        <title type="syn" xml:lang="ja">サザンアイズ</title>
        <title xml:lang="zh-x-nan" type="syn">三隻眼</title>
    </anime>
</animetitles>

i can manage to get the aid with powershell with the following

[xml]$XmlDocument = Get-Content -Path data.xml
$XmlDocument.animetitles.anime.aid

and i can get select the titel with the require id with the following

for example aid = 1 and get the titel with tag main

[xml]$XmlDocument = Get-Content -Path C:\testxml\data.xml
$XmlDocument.animetitles.anime | Where-Object {$_.aid -eq 1} | Select-Object -property title | ForEach-Object title | Where-Object {$_.type -eq 'main'}

i would like to combine both information but i dont have an idea how, i was wonder if someone can point me to the right direction? What i would like to archive is for example to have extract the information with 2 column, 1 for aid and the title info

aid and title

1 Answer 1

2

In general, you can use a combination of Where and Select-Object with calculated properties to get the information you want.

Display Both Properties with No Conditions

$XmlDocument.animetitles.anime | Select-Object aid,@{n='title';e={$_.Title.'#text'}}

Display Both Properties with Conditions

$XmlDocument.animetitles.anime |
    Where {$_.aid -eq 1} |
        Select-Object aid,@{n='title';e={$_.Title.where{$_.Type -eq 'main'}.'#text'}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.