I have a really hard time dealing with namespaces in XML myself, and realistically unless I absolutely HAVE to do it with XML, I avoid it altogether.
This is a really good read, in a general sense:
" XML Namespaces and How They Affect XPath and XSLT"
http://developers.slashdot.org/devel....shtml?tid=156
Also,
"Avoiding the Hassle of XMLNamespaceManager"
http://dotnetjunkies.com/WebLog/john...25/132153.aspx
Quote:
This is the code:
public static XmlNamespaceManager CreateNsMgr( XmlDocument doc)
{
XmlNamespaceManager nsmgr = new XmlNamespaceManager( doc.NameTable) ;
foreach ( XmlAttribute attr in doc.SelectSingleNode( "/*") .Attributes)
if ( attr.Prefix == "xmlns") nsmgr.AddNamespace( attr.LocalName, attr.Value) ;
return nsmgr;
}
This lets you write code without having to manually add in each namespace. For example the example code would be rewritten as:
XmlDocument doc = new XmlDocument( ) ;
doc.Load ("myfile.xml") ;
XmlNode result = doc.SelectSingleNode ("//my:someElement", CreateNsMgr(doc) ) ;
Note that it does assume that the namespace declarations are on the root element.
|
__________________
"I'm typing on a computer of science, which is being sent by science wires to a little science server where you can access it. I'm not typing on a computer of philosophy or religion or whatever other thing you think can be used to understand the universe because they're a poor substitute in the role of understanding the universe which exists independent from ourselves." - Willravel
Last edited by Jinn; 06-22-2007 at 10:55 AM..
Reason: Automerged Doublepost
|