0
C#でXML(xsdファイルも含む)からデータを取得します。私のコードで何が間違っているのですか: 私のXMLファイルの外観はこれが好きです。 #C#でXML Linqを照会します。
XDocument xdoc = Document.Load("document.xml") var items = from item in xdoc.Descendants("Header")
select new
{
_Item= item.Element("Item").Value,
_Item1= item.Element("Item1").Value,
_Item2= item.Element("Item2").Value,
};
foreach (var item in items)
{
Item= item._Item;
Item1 = item._Item1;
Item2 = item.Item2;
}
Console.WriteLine("show me :" + Item+ " + " + Item1 + " + " + Item2);
どのように私はヘッダーからのアイテムではなく製品やブックを抽出することができ、C
<Model_1 xmlns="http://www.3ds.com/xsd/3DXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.3ds.com/xsd/3DXML ./3DXML.xsd">
<Header>
<item></item>
<item1></item1>
<item2></item2>
</Header>
<Product>
<otheritem></otheritem>
<otheritem1></otheritem1>
<otheritem2></otheritem2>
</Product>
<Books>
<otheritem></otheritem>
<otheritem1></otheritem1>
<otheritem2></otheritem2>
</Books>
</Model_1>
...?
var ns = xdoc.Root.GetDefaultNamespace();
var header = xdoc.Root.Element(ns + "Header");
も念頭に置いておく - あなたはXMLで下ケースitem
を持って、ないItem
:あなたが名前空間を使用する必要が
のthnxは、私が試したが、それでも同じ結果ました。 – maki
@makiはあなたのXMLをコピーし、正常に解析しました。質問 –
にお送りいただいたのと同じxmlを使用していることを確認してください。それは今働く、それは私のせいだった。 – maki