i am trying to read xml data using xml reader , the xml file include alot of prefixes so i included the namespaces in an XmlNamespaceManager , example code
using (XmlReader reader = new XmlTextReader(fileName))
{
XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
nsmanager.AddNamespace("s", "http://www.google.com/shopping/api/schemas/2010");
while (reader.Read())
{
switch (reader.Name)
{
case "s:name":
Console.WriteLine(reader.Name);
break;
case "s:condition":
Console.WriteLine(reader.Name);
break;
}
}
}
its outputing empty lines, is this the right way to include the namespaces?
in vb.net i imported the namespaces as
Imports <xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Imports <xmlns:msxsl="urn:schemas-microsoft-com:xslt">
Imports <xmlns:rh="ReportHub">
Imports <xmlns="http://www.w3.org/2005/Atom">
Imports <xmlns:gd="http://schemas.google.com/g/2005">
Imports <xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
Imports <xmlns:s="http://www.google.com/shopping/api/schemas/2010">
XmlReader? I usually find that LINQ to XML makes working with namespaces much simpler.XmlReaderis significant, I wouldn't assume that you have to useXmlReader.