VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
指定した要素の属性を取得するには、要素のGetAttributesプロパティを使用します。このプロパティがTrueの場合は子要素があることを示します。
Dim xmlDoc As New System.Xml.XmlDocument 'XMLファイルを読み込む xmlDoc.Load("C:\Work\Test.xml") 'ルート要素を取得する Dim rootElement As System.Xml.XmlElement = xmlDoc.DocumentElement 'rootElementが属性を持っているか? If rootElement.HasAttributes = True Then '属性を取得する Console.WriteLine(rootElement.GetAttribute("zip")) Else Console.WriteLine("属性はありません") End If