2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

そこらへんにあるXMLファイルをC#でXElementを使って読み込むときの注意点 ~ xmlns

Last updated at Posted at 2020-11-12

まえがき

ノードの検索が引っかからなくて調べたら、
xmlns(namespace)の指定(<hogefoobar xmlns="http://example.com">みたいなの)が含まれるXMLファイルの場合、
XElement.Elements(ノード名)などを指定するときの「ノード名」として、ネームスペースを含めた文字列をしてしないと抽出できないということが分かったので、備忘を兼ねて記事を書いておきます。

XElement」とタイトルに書いてますが、XElement使わない場合もxmlnsには気を付けたほうがよさそうな予感。

ソース(雰囲気)

C#

XElement rootNode = XElement.Load("ほげほげ.xml");
XNamespace ns = rootNode.Name.Namespace;

IEnumerable<XElement> items = rootNode.Elements(ns + "ノード名");

参考サイト

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?