この記事は2008/03/11にわんくまブログで書いたものです。
PowerShell を使用して一からXmlDocumentを作成する手順を紹介します。
Step1はじめにXmlDocumentを作成します
PS C:\Work> $XmlDoc = New-Object System.Xml.XmlDocument PS C:\Work> $XmlDoc.GetType()
Step2XML宣言ノード を作成するにはXmlDeclaretionクラスを使用します。
PS C:\Work> [System.Xml.XmlDeclaration]$XmlDecl = $XmlDoc.CreateXmlDeclaration("1.0","UTF-8",$Null)
Step3ルート要素を追加する
PS C:\Work> $rootElement = $XmlDoc.CreateElement("personal_data")
Step4子要素を追加するまず、子要素を作成する
PS C:\Work> $zipElement = $XmlDoc.CreateElement("zip")
Step5子要素の値を設定する
PS C:\Work> $zipValue = $xmlDoc.CreateTextNode("012-3456") PS C:\Work> $zipElement.AppendChild($zipValue)
Step6子要素をルート要素に追加する
PS C:\Work> $rootElement.AppendChild($zipElement) #text ----- 012-3456
Step7必要な子要素分だけStep4~Step6を繰り返します。
Step8ルート要素をDOMドキュメントに追加する
PS C:\Work> $xmlDoc.AppendChild($rootElement) zip --- 012-3456
Step9作成したドキュメントをファイルに保存する
PS C:\Work> $XmlDoc.Save("C:\Work\Test.xml")
PowerShellでXmlDocumentを作成したくなったら参考にしてください。
Theme design by Jelle Druyts
Pick a theme: BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2 BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, HIRO
E-mail