我有这段代码,我正在尝试调整以仅取回消息元素:
public static void Main(string[] args)
{
Console.WriteLine("Querying tree loaded with XElement.Load");
Console.WriteLine("----");
XElement doc = XElement.Parse(@"<magento_api>
<messages>
<error>
<data_item>
<code>400</code>
<message>Attribute weight is not applicable for product type Configurable Product</message>
</data_item>
<data_item>
<code>400</code>
<message>Resource data pre-validation error.</message>
</data_item>
</error>
</messages>
</magento_api>");
IEnumerable<XElement> childList =
from el in doc.Elements()
select el;
foreach (XElement e in childList)
Console.WriteLine(e);
}
我想得到以下结果:
<message>Attribute weight is not applicable for product type Configurable Product</message>
<message>Resource data pre-validation error.</message>
我是整个查询 XElement 的新手,因此感谢您提供任何帮助。