Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
How do I make a check whether xml is empty or not
--- XML if not empty ---
<linkBox>
<widgets>
<widget isCollapsed="false">
<linkstype>interntlink</linkstype>
<boxlinktekst>test af internt link</boxlinktekst>
<eksternelinks />
<interntlink>
<contentPicker>
<content>1320</content>
</contentPicker>
</interntlink>
</widget>
<linkstype>eksternelinks</linkstype>
<boxlinktekst>test af eksterne link</boxlinktekst>
<eksternelinks>http://www.onkelb.dk</eksternelinks>;
<contentPicker />
</widgets>
</linkBox>
--- If empty -----
<linkstype />
<boxlinktekst />
Hi Brian, something like this perhaps? Do you need help reading the RSS feed in general or just checking for the value?
@if(@node.Attributes["linkstype"].InnerText.ToString() == null){do stuff}
XElement root1 = XElement.Parse( @"<linkBox> <widgets> <widget isCollapsed='false'> <linkstype /> <boxlinktekst /> <eksternelinks /> <interntlink> <contentPicker /> </interntlink> </widget> </widgets> </linkBox>"); var links1 = from x in root1.Elements("widgets").Elements("widget") where x.Element("eksternelinks").Value != "" || x.Element("interntlink").Element("contentPicker").Descendants("content").Count() > 0 select x; XElement root2 = XElement.Parse( @"<linkBox> <widgets> <widget isCollapsed='false'> <linkstype>interntlink</linkstype> <boxlinktekst>test af internt link</boxlinktekst> <eksternelinks /> <interntlink> <contentPicker> <content>1320</content> </contentPicker> </interntlink> </widget> <widget isCollapsed='false'> <linkstype>eksternelinks</linkstype> <boxlinktekst>test af eksterne link</boxlinktekst> <eksternelinks>http://www.onkelb.dk</eksternelinks>; <interntlink> <contentPicker /> </interntlink> </widget> </widgets> </linkBox>"); var links2 = from x in root2.Elements("widgets").Elements("widget") where x.Element("eksternelinks").Value != "" || x.Element("interntlink").Element("contentPicker").Descendants("content").Count() > 0 select x;
links1 should return empty
links2 should return 2 items
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor check whether item is empty or not in xml
How do I make a check whether xml is empty or not
--- XML if not empty ---
<linkBox>
<widgets>
<widget isCollapsed="false">
<linkstype>interntlink</linkstype>
<boxlinktekst>test af internt link</boxlinktekst>
<eksternelinks />
<interntlink>
<contentPicker>
<content>1320</content>
</contentPicker>
</interntlink>
</widget>
<widget isCollapsed="false">
<linkstype>eksternelinks</linkstype>
<boxlinktekst>test af eksterne link</boxlinktekst>
<eksternelinks>http://www.onkelb.dk</eksternelinks>;
<interntlink>
<contentPicker />
</interntlink>
</widget>
</widgets>
</linkBox>
--- If empty -----
<linkBox>
<widgets>
<widget isCollapsed="false">
<linkstype />
<boxlinktekst />
<eksternelinks />
<interntlink>
<contentPicker />
</interntlink>
</widget>
</widgets>
</linkBox>
Hi Brian, something like this perhaps? Do you need help reading the RSS feed in general or just checking for the value?
links1 should return empty
links2 should return 2 items
is working on a reply...