My XML document has a default namespace specified by xmlns="some_url". Here
it is:
<?xml version="1.0" encoding="utf-8" ?>
<ssmproject
name="sample" server="sql"
xmlns="mailto:ne***********@msn.com?subject=ssmprj x"
<pr>
<script name="pr_sample_script_name" />
</pr>
</ssmproject>
I load it with XmlDocument.Load(filename). I have problem with
SelectSingleNode. The following code will return null:
m_doc.SelectSingleNode("/ssmproject");
I can work around this problem by using a Namespace manager and the 2nd form
of SelectSingleNode:
m_nsmgr = new XmlNamespaceManager(m_doc.NameTable);
m_nsmgr.AddNamespace("tns", "mailto:ne***********@msn.com?subject=ssmprjx" );
m_doc.SelectSingleNode("/tns:ssmproject", m_nsmgr);
But I have to add the prefix tns before every element in the XPath string,
e.g., /tns:ssmproject/tns:pr/tns:script. This is not good.
I'm not very familiar with XML namespace resolution. I was thinking that a
default namespace will do this:
m_nsmgr.AddNamespace(string.Empty,
"mailto:ne***********@msn.com?subject=ssmprjx" );
But I was wrong. Even I added this default namespace, the code
m_doc.SelectSingleNode("/ssmproject", m_nsmgr);
still returned null.
Was I missing something important?