问题描述
我想拉< thumbnail_large> HTTP://b.vimeocdn.com/ts/235/662/23566238_640.jpg< / thumbnail_large>
价值从创建的XML文件thumbnail_large元素。有没有办法去拉该值不通过谁xml文件循环? 。感谢您的帮助。
<视频和GT;
<视频>
<&ID GT; 6271487< / ID>
<标题>&球LT; /标题>
<描述>文字< /描述>
< URL> HTTP://vimeo.com/6271487< / URL>
< thumbnail_small> HTTP://b.vimeocdn.com/ts/235/662/23566238_100.jpg< / thumbnail_small>
< thumbnail_medium> HTTP://b.vimeocdn.com/ts/235/662/23566238_200.jpg< / thumbnail_medium>
< thumbnail_large> HTTP://b.vimeocdn.com/ts/235/662/23566238_640.jpg< / thumbnail_large>
< embed_privacy>任何地方和LT; / embed_privacy>
< /视频>
< /视频>
对了,还有,它被称为XPath的。试试这个:
XmlDocument的DOC =新的XmlDocument();
doc.Load(@/路径/到/文件);
XmlNode的节点= doc.SelectSingleNode(/影片/视频/ thumbnail_large);
字符串URI = node.InnerText;
至少这是我可以从这个糟糕的格式文件读取。如果您使用的是两个不同的字母(视频细节和HTML标记),你应该考虑使用的命名空间。
I am trying to pull the <thumbnail_large>http://b.vimeocdn.com/ts/235/662/23566238_640.jpg</thumbnail_large>
value from the thumbnail_large element in a created xml file. Is there a way to pull that value without looping through the who xml file? Thanks for any help.
<videos>
<video>
<id>6271487</id>
<title>Spheres</title>
<description>text</description>
<url>http://vimeo.com/6271487</url>
<thumbnail_small>http://b.vimeocdn.com/ts/235/662/23566238_100.jpg</thumbnail_small>
<thumbnail_medium>http://b.vimeocdn.com/ts/235/662/23566238_200.jpg</thumbnail_medium>
<thumbnail_large>http://b.vimeocdn.com/ts/235/662/23566238_640.jpg</thumbnail_large>
<embed_privacy>anywhere</embed_privacy>
</video>
</videos>
Yes, there is and it is called XPath. Try this:
XmlDocument doc = new XmlDocument();
doc.Load(@"/path/to/file");
XmlNode node = doc.SelectSingleNode("/videos/video/thumbnail_large");
string URI = node.InnerText;
At least that is what I can read from this poorly formatted file. If you are using two different alphabets (video details and HTML markup) you should consider using namespaces.
这篇关于C#读取XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!