我可以在给定的XML节点中获得p3:type的值吗? [英] Ho can I get value of p3:type in the given XML Node?

查看:53
本文介绍了我可以在给定的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 the System.Xml.Linq namespace.

You just need an XNamespace for the URI of the p3 namespace, which you then use to create an XName 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆