Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# reading xml file

Tags:

c#

.net

xml

xpath

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>
like image 474
user516883 Avatar asked Mar 07 '26 21:03

user516883


1 Answers

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.

like image 189
Jan Avatar answered Mar 10 '26 11:03

Jan