Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 27, 2012 05:45 AM by kuber.manral
Member
48 Points
84 Posts
Feb 27, 2012 03:55 AM|LINK
Hi I have a rss link for fetching xml data but I cannot read one node which has dates however I am able to read title and description.
<a10:updated>2012-02-23T11:50:00-08:00</a10:updated>
Here is my code
string RssUrl = string.Empty;
RssUrl = "http://www.eetimes.com/RSS/RSSResult?contentType=10&contentSubtype=RF/Microwave&classificationGroupId=35";
WebRequest MyRssRequest = WebRequest.Create(RssUrl);
WebResponse MyRssResponse = MyRssRequest.GetResponse();
Stream MyRssStream = MyRssResponse.GetResponseStream();
XmlDocument MyRssDocument = new XmlDocument();
MyRssDocument.Load(MyRssStream);
XmlNodeList MyRssList = MyRssDocument.SelectNodes("rss/channel/item");
string sTitle = "";
string sLink = "";
string sDescription = "";
string sdate = "";
for (int i = 0; i < MyRssList.Count; i++)
{
XmlNode MyRssDetail;
MyRssDetail = MyRssList.Item(i).SelectSingleNode("title");
if (MyRssDetail != null)
sTitle = MyRssDetail.InnerText;
else
sTitle = "";
MyRssDetail = MyRssList.Item(i).SelectSingleNode("description");
sDescription = MyRssDetail.InnerText;
sDescription = "";
}
MyRssDetail = MyRssList.Item(i).SelectSingleNode("link");
sLink = MyRssDetail.InnerText;
sLink = "";
MyRssDetail = MyRssList.Item(i).SelectSingleNode("a10:updated");
sdate = MyRssDetail.InnerText;
sdate = "";
Please Help
Contributor
3051 Points
714 Posts
Feb 27, 2012 04:15 AM|LINK
Hi, Will you Please show us input XMl file data ? I think, we need to set namespaces in our XML file to read this type of Nodes.
Feb 27, 2012 04:29 AM|LINK
hi see the url in chrome u can see the xml view
http://www.eetimes.com/RSS/RSSResult?contentType=10&contentSubtype=RF/Microwave&classificationGroupId=35
Thanks
Feb 27, 2012 05:45 AM|LINK
Hi, Here is the solution. You need to add namespace there manually in your XML file. Please find the sample code below :
string _orgXM = System.IO.File.ReadAllText(Server.MapPath("~/XML/XMLFile2.xml")); XmlDocument _xmlDOc = new XmlDocument(); _xmlDOc.LoadXml(_orgXM.ToString());
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(_xmlDOc.NameTable); namespaceManager.AddNamespace("a10", "http://www.w3.org/2005/Atom");
XmlNodeList MyRssList = _xmlDOc.SelectNodes("rss/channel/item"); XmlNode MyRssDetail;
MyRssDetail = MyRssList.Item(0).SelectSingleNode("a10:updated", namespaceManager); Response.Write("a10:updated : " + MyRssDetail.InnerText);
For more, try below Link: http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.addnamespace.aspx
Hope it helps...
yogeshweb
Member
48 Points
84 Posts
Not Abe to Read Xml Date Node
Feb 27, 2012 03:55 AM|LINK
Here is my code
string RssUrl = string.Empty;
RssUrl = "http://www.eetimes.com/RSS/RSSResult?contentType=10&contentSubtype=RF/Microwave&classificationGroupId=35";
WebRequest MyRssRequest = WebRequest.Create(RssUrl);
WebResponse MyRssResponse = MyRssRequest.GetResponse();
Stream MyRssStream = MyRssResponse.GetResponseStream();
XmlDocument MyRssDocument = new XmlDocument();
MyRssDocument.Load(MyRssStream);
XmlNodeList MyRssList = MyRssDocument.SelectNodes("rss/channel/item");
string sTitle = "";
string sLink = "";
string sDescription = "";
string sdate = "";
for (int i = 0; i < MyRssList.Count; i++)
{
XmlNode MyRssDetail;
MyRssDetail = MyRssList.Item(i).SelectSingleNode("title");
if (MyRssDetail != null)
sTitle = MyRssDetail.InnerText;
else
sTitle = "";
MyRssDetail = MyRssList.Item(i).SelectSingleNode("description");
if (MyRssDetail != null)
sDescription = MyRssDetail.InnerText;
else
{
sDescription = "";
}
MyRssDetail = MyRssList.Item(i).SelectSingleNode("link");
if (MyRssDetail != null)
sLink = MyRssDetail.InnerText;
else
sLink = "";
MyRssDetail = MyRssList.Item(i).SelectSingleNode("a10:updated");
if (MyRssDetail != null)
sdate = MyRssDetail.InnerText;
else
{
sdate = "";
}
Please Help
kuber.manral
Contributor
3051 Points
714 Posts
Re: Not Abe to Read Xml Date Node
Feb 27, 2012 04:15 AM|LINK
Hi,
Will you Please show us input XMl file data ? I think, we need to set namespaces in our XML file to read this type of Nodes.
Visit My Blog
yogeshweb
Member
48 Points
84 Posts
Re: Not Abe to Read Xml Date Node
Feb 27, 2012 04:29 AM|LINK
hi see the url in chrome u can see the xml view
http://www.eetimes.com/RSS/RSSResult?contentType=10&contentSubtype=RF/Microwave&classificationGroupId=35
Thanks
kuber.manral
Contributor
3051 Points
714 Posts
Re: Not Abe to Read Xml Date Node
Feb 27, 2012 05:45 AM|LINK
Hi,
Here is the solution. You need to add namespace there manually in your XML file. Please find the sample code below :
string _orgXM = System.IO.File.ReadAllText(Server.MapPath("~/XML/XMLFile2.xml"));
XmlDocument _xmlDOc = new XmlDocument();
_xmlDOc.LoadXml(_orgXM.ToString());
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(_xmlDOc.NameTable);
namespaceManager.AddNamespace("a10", "http://www.w3.org/2005/Atom");
XmlNodeList MyRssList = _xmlDOc.SelectNodes("rss/channel/item");
XmlNode MyRssDetail;
MyRssDetail = MyRssList.Item(0).SelectSingleNode("a10:updated", namespaceManager);
Response.Write("a10:updated : " + MyRssDetail.InnerText);
For more, try below Link:
http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.addnamespace.aspx
Hope it helps...
Visit My Blog