I have this string structured as XML:
<damp fullmedia="">
<mediaitem>
<img id="1119" version="29a5623f-d41c-4418-97b7-3cea8579ffd8" parentid="1052" level="2" writerid="0" nodetype="1032" template="0" sortorder="2" createdate="2016-11-30T10:09:40" updatedate="2016-11-30T10:09:40" nodename="2016-11-25_1251411957-277" urlname="2016-11-25_1251411957-277" writername="admin" nodetypealias="Image" path="-1,1052,1119">
<umbracofile>/media/1013/2016-11-25_1251411957-277.jpg</umbracofile>
<umbracowidth>2598</umbracowidth>
<umbracoheight>1732</umbracoheight>
<umbracobytes>350613</umbracobytes>
<umbracoextension>jpg</umbracoextension>
</img>
</mediaitem>
</damp>
I want to extract the value of property "umbracofile", so I did this:
var stringAsXml = "<damp fullmedia="">....";
var xmlDoc = new XmlDocument();
var imageUrl = xmlDoc.SelectSingleNode("//mediaItem/img/umbracoFile").InnerText;
The code works fine but I have the error "Root element is missing". As I just want to parse and extract a node value, how can I get rid of this error?
The code works fine but I have the errorI'd argue that these statements are actually contradictory. Error might be related to fact that you are looking for nodeImagewhen the node is actuallyimgimgtag is also never closed. I don't know if that's a typo