前提・実現したい事
①PowerShellを使用し、SharePoint Online上のリストを、「XMLファイル」でローカルに保存する。。
(*プログラム作成済)
【保存したXMLファイル】
XML
1<?xml version= "1.0"?> 2<catalog> 3 4 <book id= "bk101"> 5 <author>Gambardella, Matthew</author> 6 <title>XML Developer's Guide</title> 7 <genre>Computer</genre> 8 <price>44.95</price> 9 <publish_date>2000-10-01</publish_date> 10 <description>An in-depth look at creating applicationswith XML.</description> 11 </book> 12 13 <book id= "bk102"> 14 <author>Ralls, Kim</author> 15 <title>Midnight Rain</title> 16 <genre>Fantasy</genre> 17 <price>5.95</price> 18 <publish_date>2000-12-16</publish_date> 19 <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> 20 </book> 21 22 <book id= "bk103"> 23 <author>Corets, Eva</author> 24 <title>Maeve Ascendant</title> 25 <genre>Fantasy</genre> 26 <price>5.95</price> 27 <publish_date>2000-11-17</publish_date> 28 <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description> 29 </book> 30 31 <book id= "bk104"> 32 <author>Corets, Eva</author> 33 <title>Oberon's Legacy</title> 34 <genre>Fantasy</genre> 35 <price>5.95</price> 36 <publish_date>2001-03-10</publish_date> 37 <description>In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.</description> 38 </book> 39 40 <book id= "bk105"> 41 <author>Corets, Eva</author> 42 <title>The Sundered Grail</title> 43 <genre>Fantasy</genre> 44 <price>5.95</price> 45 <publish_date>2001-09-10</publish_date> 46 <description>The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.</description> 47 </book> 48 49 <book id= "bk106"> 50 <author>Randall, Cynthia</author> 51 <title>Lover Birds</title> 52 <genre>Romance</genre> 53 <price>4.95</price> 54 <publish_date>2000-09-02</publish_date> 55 <description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description> 56 </book> 57 58 <book id= "bk107"> 59 <author>Thurman, Paula</author> 60 <title>Splish Splash</title> 61 <genre>Romance</genre> 62 <price>4.95</price> 63 <publish_date>2000-11-02</publish_date> 64 <description>A deep sea diver finds true love twenty thousand leagues beneath the sea.</description> 65 </book> 66 67 <book id= "bk108"> 68 <author>Knorr, Stefan</author> 69 <title>Creepy Crawlies</title> 70 <genre>Horror</genre> 71 <price>4.95</price> 72 <publish_date>2000-12-06</publish_date> 73 <description>An anthology of horror stories about roaches, centipedes, scorpions and other insects.</description> 74 </book> 75 76 <book id= "bk109"> 77 <author>Kress, Peter</author> 78 <title>Paradox Lost</title> 79 <genre>Science Fiction</genre> 80 <price>6.95</price> 81 <publish_date>2000-11-02</publish_date> 82 <description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description> 83 </book> 84 85 <book id= "bk110"> 86 <author>O'Brien, Tim</author> 87 <title>Microsoft .NET: The Programming Bible</title> 88 <genre>Computer</genre> 89 <price>36.95</price> 90 <publish_date>2000-12-09</publish_date> 91 <description>Microsoft's .NET initiative is explored in detail in this deep programmer's reference.</description> 92 </book> 93 94 <book id= "bk111"> 95 <author>O'Brien, Tim</author> 96 <title>MSXML3: A Comprehensive Guide</title> 97 <genre>Computer</genre> 98 <price>36.95</price> 99 <publish_date>2000-12-01</publish_date> 100 <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description> 101 </book> 102 103 <book id= "bk112"> 104 <author>Galos, Mike</author> 105 <title>Visual Studio 7: A Comprehensive Guide</title> 106 <genre>Computer</genre> 107 <price>49.95</price> 108 <publish_date>2001-04-16</publish_date> 109 <description>Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.</description> 110 </book> 111</catalog>
↓
②保存したXMLファイルの中には、不要な項目(タグ)があるので、PowerShellを使い必要なタグのみ抽出。(別名で保存)
(*プログラム作成済)
【作成したプログラム】
PowerShell
1# 変数宣言 2$XmlFilePath = "XMLファイル保存先パス" 3$XmlSavePath = "保存先パス" 4$TagName = "'title','genre','price'" # 抜き出したいタグ名 5 6# XMLファイル読み込み 7$xml = [xml](Get-Content $XmlFilePath) 8 9# XMLタグ抜き出し 10$CustomXML = $xml.catalog.book | 11 ForEach-Object { 12 $_[$TagName].OuterXml 13 } 14 15# ファイル出力(文字コード:UTF8) 16$CustomXML | Out-File $XmlSavePath -Encoding UTF8
【必要なタグのみ抽出したXMLファイル】抽出するタグ名 → title, genre, price
XML
1<title>XML Developer's Guide</title> 2<genre>Computer</genre> 3<price>44.95</price> 4<title>Midnight Rain</title> 5<genre>Fantasy</genre> 6<price>5.95</price> 7<title>Maeve Ascendant</title> 8<genre>Fantasy</genre> 9<price>5.95</price> 10<title>Oberon's Legacy</title> 11<genre>Fantasy</genre> 12<price>5.95</price> 13<title>The Sundered Grail</title> 14<genre>Fantasy</genre> 15<price>5.95</price> 16<title>Lover Birds</title> 17<genre>Romance</genre> 18<price>4.95</price> 19<title>Splish Splash</title> 20<genre>Romance</genre> 21<price>4.95</price> 22<title>Creepy Crawlies</title> 23<genre>Horror</genre> 24<price>4.95</price> 25<title>Paradox Lost</title> 26<genre>Science Fiction</genre> 27<price>6.95</price> 28<title>Microsoft .NET: The Programming Bible</title> 29<genre>Computer</genre> 30<price>36.95</price> 31<title>MSXML3: A Comprehensive Guide</title> 32<genre>Computer</genre> 33<price>36.95</price> 34<title>Visual Studio 7: A Comprehensive Guide</title> 35<genre>Computer</genre> 36<price>49.95</price>
↓
③必要なタグのみ抽出したXMLファイルを開くと、必要な項目(タグ)のみ抽出されてはいるが、見づらいので
1アイテム毎にタグでくくり、見やすくしたい。
*(プログラム作成中。不明点)
【この様なXMLファイルにしたい】
XML
1 2<data> 3 <title>XML Developer's Guide</title> 4 <genre>Computer</genre> 5 <price>44.95</price> 6</data> 7<data> 8 <title>Midnight Rain</title> 9 <genre>Fantasy</genre> 10 <price>5.95</price> 11</data> 12<data> 13 <title>Maeve Ascendant</title> 14 <genre>Fantasy</genre> 15 <price>5.95</price> 16</data> 17<data> 18 <title>Oberon's Legacy</title> 19 <genre>Fantasy</genre> 20 <price>5.95</price> 21</data> 22<data> 23 <title>The Sundered Grail</title> 24 <genre>Fantasy</genre> 25 <price>5.95</price> 26</data> 27<data> 28 <title>Lover Birds</title> 29 <genre>Romance</genre> 30 <price>4.95</price> 31</data> 32<data> 33 <title>Splish Splash</title> 34 <genre>Romance</genre> 35 <price>4.95</price> 36</data> 37<data> 38 <title>Creepy Crawlies</title> 39 <genre>Horror</genre> 40 <price>4.95</price> 41</data> 42<data> 43 <title>Paradox Lost</title> 44 <genre>Science Fiction</genre> 45 <price>6.95</price> 46</data> 47<data> 48 <title>Microsoft .NET: The Programming Bible</title> 49 <genre>Computer</genre> 50 <price>36.95</price> 51</data> 52<data> 53 <title>MSXML3: A Comprehensive Guide</title> 54 <genre>Computer</genre> 55 <price>36.95</price> 56</data> 57<data> 58 <title>Visual Studio 7: A Comprehensive Guide</title> 59 <genre>Computer</genre> 60 <price>49.95</price> 61</data>
発生している問題・Error Message
③のコード記述が分からず困っております。
もし、分かる方がいれば、よろしくお願い致します。。
実際のソースコード
試した事
補足情報(言語/FW/ツール等のVersion)
・PowerShell ver5.0
・SharePoint Online
・Windows 7
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。