我可以在给定的XML节点中获得p3:type的值吗? [英] Ho can I get value of p3:type in the given XML Node?
本文介绍了我可以在给定的XML节点中获得p3:type的值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< hero_banner>
< image p3:type =simplep3:href =tcm:86-10894p3:title =tpw-event-large-7xmlns :p3 =http://www.w3.org/1999/xlink>< / image>
< lower_text>图片1标题
<hero_banner>
<image p3:type="simple" p3:href="tcm:86-10894" p3:title="tpw-event-large-7" xmlns:p3="http://www.w3.org/1999/xlink"></image>
<lower_text>Image 1 Caption
推荐答案
鉴于标签,我假设你正在使用 LINQ to XML [ ^ ]和System.Xml.Linq
命名空间。
你只需要一个XNamespace
表示p3
命名空间的URI,然后您可以使用该命名空间创建XName
属性名称。
例如:
Given the tags, I'm assuming that you're using LINQ to XML[^] and theSystem.Xml.Linq
namespace.
You just need anXNamespace
for the URI of thep3
namespace, which you then use to create anXName
for the attribute name.
For example:
var element = XElement.Parse(@"<image p3:type=""simple"" p3:href=""tcm:86-10894"" p3:title=""tpw-event-large-7"" xmlns:p3=""http://www.w3.org/1999/xlink""></image>");
XNamespace p3 = "http://www.w3.org/1999/xlink";
XName attributeName = p3 + "type";
string type = (string)element.Attribute(attributeName);
Console.WriteLine(type);
这篇关于我可以在给定的XML节点中获得p3:type的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文