EDN Admin
Well-known member
I was trying to filter MY XML data, but i am having problem to get distinct attributes from "onl:stories/onl:story". I want to get the "onl:stories/onl:story" attributes key value, The below code works but return the same value for each item
topStory.strStoryID = xmlDoc.SelectSingleNode("onl:stories/onl:story", namespaceManager).Attributes["key"].InnerText.Replace("{", "").Replace("}", "");
Please help.
Here is My C# Code <br/>
XmlDocument xmlDoc = new XmlDocument();<br/>
//xmlDoc.LoadXml(Return_XmLFeedByURL("http://jpedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories&categories=CPBJ01"));<br/>
xmlDoc.LoadXml(Return_XmLFeedByURL("http://jpedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories&categories=" + strCategory));<br/>
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);<br/>
namespaceManager.AddNamespace("onl", "http://www.saxotech.com/online");<br/>
XmlNodeList StoryItems = xmlDoc.SelectNodes("onl:stories/onl:story/onl:content", namespaceManager);<br/>
for (int i = 0; i <= StoryItems.Count - 1; i++)<br/>
{<br/>
if (StoryItems.Item(i).SelectSingleNode("onl:image", namespaceManager) != null)<br/>
{<br/>
Top10TopStories topStory = new Top10TopStories();<br/>
topStory.strStoryID = xmlDoc.SelectSingleNode("onl:stories/onl:story", namespaceManager).Attributes["key"].InnerText.Replace("{",
"").Replace("}", "");<br/>
topStory.strNHeading = StoryItems.Item(i).SelectSingleNode("onl:heading", namespaceManager).InnerText;<br/>
topStory.strNThumb = "http://jpedit.sx.atl.publicus.com" + StoryItems.Item(i).SelectSingleNode("onl:image", namespaceManager).Attributes["viewuri"].InnerText;<br/>
newsDetails.Add(topStory);<br/>
}<br/>
}
My XML File: <br/>
<?xml version="1.0" encoding="UTF-8"?><br/>
<onl:stories xmlnsnl="http://www.saxotech.com/online" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.saxotech.com/online stories.xsd" site="jp" siteuri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp" count="10"
totalcount="144" pagenumber="1" pagesize="10" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories <br/>
<onl:story date="20121107" id="121109843" key="{13D80928-73F8-4209-B36C-F682D6F64B84}" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}" viewuri="http://JPedit.sx.atl.publicus.com/article/20121107/BOY/121109843 <br/>
<onl:metadata status="unpublished" priority="0 <br/>
<onl:modified by="colleenj" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{97A9E7BD-6311-41EC-9FBA-B7D347E44A9C}" timestamp="2012-11-07T21:50:46Z" internaltimestamp="2012-11-07T22:17:49Z" /><br/>
<onl:created by="colleenj" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{97A9E7BD-6311-41EC-9FBA-B7D347E44A9C}" timestamp="2012-11-07T21:50:46Z" /><br/>
<onlublished timestamp="2012-11-07T21:50:46Z" /><br/>
<onl:category id="BOY" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/categories/BOY <![CDATA[Event - Business of the Year]]></onl:category><br/>
</onl:metadata><br/>
<onl:content><br/>
<onl:heading><![CDATA[A Trbiute to Conrad M. Siegel]]></onl:heading><br/>
<onl:summary><![CDATA[A brief tribute video created by FGV and the Central Penn Business Journal to recognize Conrad M. Siegel, founder, chairman and CEO of Conrad Siegel Actuaries upon his induction into the Central
Penn Business Hall of Fame on November 1, 2012.<br/>
<br/>
http://www.cpbjnow.com/assets/mov/JP127109117.WMV Click here to watch the video. ]]></onl:summary><br/>
<onl:image viewuri="/storyimage/jp/20121107/BOY/121109843/AR/0/0/AR-121109843.jpg" softcropimagesuri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/content/image/softcropimages <br/>
<onl:heading><![CDATA[Conrad M. Siegel]]></onl:heading><br/>
<onl:byline><![CDATA[Amy Spangler]]></onl:byline><br/>
</onl:image><br/>
</onl:content><br/>
<onlarents count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/parents" /><br/>
<onl:children count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/children" /><br/>
<onl:taxonomywords count="1" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/taxonomywords" /><br/>
<onl:geopoints count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/geopoints" /><br/>
<onl:extraimages count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/content/extraimages" /><br/>
<onl:mediafiles count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/content/mediafiles" /><br/>
<onl:staffmembers count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/staffmembers" /><br/>
<onl:comments count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/comments" /><br/>
</onl:story><br/>
<onl:story date="20121107" id="121109844" key="{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}" viewuri="http://JPedit.sx.atl.publicus.com/article/20121107/SPORTS/121109844 <br/>
<onl:metadata status="published" priority="0 <br/>
<onl:modified by="amyg" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{D448C507-2C34-4BC1-9D8D-34360D50DB55}" timestamp="2012-11-07T20:25:35Z" internaltimestamp="2012-11-07T20:27:10Z" /><br/>
<onl:created by="amyg" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{D448C507-2C34-4BC1-9D8D-34360D50DB55}" timestamp="2012-11-07T20:25:35Z" /><br/>
<onlublished timestamp="2012-11-07T20:00:00Z" /><br/>
<onl:category id="SPORTS" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/categories/SPORTS <![CDATA[Blog - Sports]]></onl:category><br/>
</onl:metadata><br/>
<onl:content><br/>
<onl:heading><![CDATA[Concessions: Quite the moneymaker for stadiums]]></onl:heading><br/>
<onl:summary><![CDATA[There’s a reason “Take Me Out To The Ballgame” includes a verse about peanuts and Cracker Jack. Even as far back as 1908, when the song was written, concessions were
an important part of the fan experience – and the team’s bottom line. ]]></onl:summary><br/>
<onl:byline><![CDATA[Bill Sayer]]></onl:byline><br/>
</onl:content><br/>
<onlarents count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/parents" /><br/>
<onl:children count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/children" /><br/>
<onl:taxonomywords count="1" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/taxonomywords" /><br/>
<onl:geopoints count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/geopoints" /><br/>
<onl:extraimages count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/content/extraimages" /><br/>
<onl:mediafiles count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/content/mediafiles" /><br/>
<onl:staffmembers count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/staffmembers" /><br/>
<onl:comments count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/comments" /><br/>
</onl:story><br/>
</onl:stories>
View the full article
topStory.strStoryID = xmlDoc.SelectSingleNode("onl:stories/onl:story", namespaceManager).Attributes["key"].InnerText.Replace("{", "").Replace("}", "");
Please help.
Here is My C# Code <br/>
XmlDocument xmlDoc = new XmlDocument();<br/>
//xmlDoc.LoadXml(Return_XmLFeedByURL("http://jpedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories&categories=CPBJ01"));<br/>
xmlDoc.LoadXml(Return_XmLFeedByURL("http://jpedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories&categories=" + strCategory));<br/>
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);<br/>
namespaceManager.AddNamespace("onl", "http://www.saxotech.com/online");<br/>
XmlNodeList StoryItems = xmlDoc.SelectNodes("onl:stories/onl:story/onl:content", namespaceManager);<br/>
for (int i = 0; i <= StoryItems.Count - 1; i++)<br/>
{<br/>
if (StoryItems.Item(i).SelectSingleNode("onl:image", namespaceManager) != null)<br/>
{<br/>
Top10TopStories topStory = new Top10TopStories();<br/>
topStory.strStoryID = xmlDoc.SelectSingleNode("onl:stories/onl:story", namespaceManager).Attributes["key"].InnerText.Replace("{",
"").Replace("}", "");<br/>
topStory.strNHeading = StoryItems.Item(i).SelectSingleNode("onl:heading", namespaceManager).InnerText;<br/>
topStory.strNThumb = "http://jpedit.sx.atl.publicus.com" + StoryItems.Item(i).SelectSingleNode("onl:image", namespaceManager).Attributes["viewuri"].InnerText;<br/>
newsDetails.Add(topStory);<br/>
}<br/>
}
My XML File: <br/>
<?xml version="1.0" encoding="UTF-8"?><br/>
<onl:stories xmlnsnl="http://www.saxotech.com/online" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.saxotech.com/online stories.xsd" site="jp" siteuri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp" count="10"
totalcount="144" pagenumber="1" pagesize="10" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories <br/>
<onl:story date="20121107" id="121109843" key="{13D80928-73F8-4209-B36C-F682D6F64B84}" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}" viewuri="http://JPedit.sx.atl.publicus.com/article/20121107/BOY/121109843 <br/>
<onl:metadata status="unpublished" priority="0 <br/>
<onl:modified by="colleenj" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{97A9E7BD-6311-41EC-9FBA-B7D347E44A9C}" timestamp="2012-11-07T21:50:46Z" internaltimestamp="2012-11-07T22:17:49Z" /><br/>
<onl:created by="colleenj" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{97A9E7BD-6311-41EC-9FBA-B7D347E44A9C}" timestamp="2012-11-07T21:50:46Z" /><br/>
<onlublished timestamp="2012-11-07T21:50:46Z" /><br/>
<onl:category id="BOY" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/categories/BOY <![CDATA[Event - Business of the Year]]></onl:category><br/>
</onl:metadata><br/>
<onl:content><br/>
<onl:heading><![CDATA[A Trbiute to Conrad M. Siegel]]></onl:heading><br/>
<onl:summary><![CDATA[A brief tribute video created by FGV and the Central Penn Business Journal to recognize Conrad M. Siegel, founder, chairman and CEO of Conrad Siegel Actuaries upon his induction into the Central
Penn Business Hall of Fame on November 1, 2012.<br/>
<br/>
http://www.cpbjnow.com/assets/mov/JP127109117.WMV Click here to watch the video. ]]></onl:summary><br/>
<onl:image viewuri="/storyimage/jp/20121107/BOY/121109843/AR/0/0/AR-121109843.jpg" softcropimagesuri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/content/image/softcropimages <br/>
<onl:heading><![CDATA[Conrad M. Siegel]]></onl:heading><br/>
<onl:byline><![CDATA[Amy Spangler]]></onl:byline><br/>
</onl:image><br/>
</onl:content><br/>
<onlarents count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/parents" /><br/>
<onl:children count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/children" /><br/>
<onl:taxonomywords count="1" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/taxonomywords" /><br/>
<onl:geopoints count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/geopoints" /><br/>
<onl:extraimages count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/content/extraimages" /><br/>
<onl:mediafiles count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/content/mediafiles" /><br/>
<onl:staffmembers count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/staffmembers" /><br/>
<onl:comments count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{13D80928-73F8-4209-B36C-F682D6F64B84}/comments" /><br/>
</onl:story><br/>
<onl:story date="20121107" id="121109844" key="{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}" viewuri="http://JPedit.sx.atl.publicus.com/article/20121107/SPORTS/121109844 <br/>
<onl:metadata status="published" priority="0 <br/>
<onl:modified by="amyg" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{D448C507-2C34-4BC1-9D8D-34360D50DB55}" timestamp="2012-11-07T20:25:35Z" internaltimestamp="2012-11-07T20:27:10Z" /><br/>
<onl:created by="amyg" user="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/users/{D448C507-2C34-4BC1-9D8D-34360D50DB55}" timestamp="2012-11-07T20:25:35Z" /><br/>
<onlublished timestamp="2012-11-07T20:00:00Z" /><br/>
<onl:category id="SPORTS" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/categories/SPORTS <![CDATA[Blog - Sports]]></onl:category><br/>
</onl:metadata><br/>
<onl:content><br/>
<onl:heading><![CDATA[Concessions: Quite the moneymaker for stadiums]]></onl:heading><br/>
<onl:summary><![CDATA[There’s a reason “Take Me Out To The Ballgame” includes a verse about peanuts and Cracker Jack. Even as far back as 1908, when the song was written, concessions were
an important part of the fan experience – and the team’s bottom line. ]]></onl:summary><br/>
<onl:byline><![CDATA[Bill Sayer]]></onl:byline><br/>
</onl:content><br/>
<onlarents count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/parents" /><br/>
<onl:children count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/children" /><br/>
<onl:taxonomywords count="1" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/taxonomywords" /><br/>
<onl:geopoints count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/geopoints" /><br/>
<onl:extraimages count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/content/extraimages" /><br/>
<onl:mediafiles count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/content/mediafiles" /><br/>
<onl:staffmembers count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/staffmembers" /><br/>
<onl:comments count="0" uri="http://JPedit.sx.atl.publicus.com/apps/ows.dll/sites/jp/stories/{AB1DACF8-C54D-42F4-BCB3-C820260D3CB9}/comments" /><br/>
</onl:story><br/>
</onl:stories>
View the full article