ano wrote:
Anyone knows how to get "xmlns" value from XML file?
The XmlReader will show them as attribute nodes in the predefined
namespace
http://www.w3.org/2000/xmlns/ so a C#/NET 2.0 snippet like this
using (XmlReader xmlReader = XmlReader.Create(@"file.xml")) {
while (xmlReader.Read()) {
if (xmlReader.NodeType == XmlNodeType.Element) {
while (xmlReader.MoveToNextAttribute()) {
if (xmlReader.NamespaceURI ==
"http://www.w3.org/2000/xmlns/") {
Console.WriteLine("Found namespace declaration
{0}=\"{1}\".", xmlReader.Name, xmlReader.Value);
}
}
}
}
}
will read through the complete XML document and output all namespace
declarations found. For C#/NET 1.x simply use e.g. new
XmlTextReader(@"file.xml") instead of XmlReader.Create(@"file.xml").
If you want to use another API then tell us which one exactly and we can
tell you how to look for namespace declarations (hint: in the XPath data
model namespace declarations are _not_ attributes so there you need to
seearch the namespace axis).
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/