Hi;
Ok, so in this case everything is under that namespace and I need to use it
for all nodes?
Which brings up a new question. This is for an app.dll.config file. Very
weird case - it is for a Word AddIn and we are supposed to not use
winword.exe.config but instead create an addin.dll.config and read from that.
The problem is the xmlns=... may be in the file. I have seen config files
with it and config files without it. So How do I do a select that handles
both cases?
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com Cubicle Wars -
http://www.windwardreports.com/film.htm [quoted text, click to view] "Martin Honnen" wrote:
> David Thielen wrote:
>
> > If I have the xml:
> > <?xml version="1.0"?>
> > <configuration xmlns="
http://schemas.microsoft.com/.NetConfiguration/v2.0">
> > ...
> >
> > What is the xpath in XmlDocument.SelectNodes() to get the root node? I
> > thought it was "/configuration" as the namespace is the default - but that
> > does not work.
>
> Choose a prefix for your elements e.g. nc, then use an XmlNamespaceManager
> XmlNamespaceManager namespaceManager = new
> XmlNamespaceManager(yourXmlDocumentInstance.NameTable);
> namespaceManager.AddNamespace("nc",
> "
http://schemas.microsoft.com/.NetConfiguration/v2.0");
> then use that prefix in your XPath expressions and pass in the namespace
> manager as the second argument to SelectNodes/SelectSingleNode e.g.
> yourXmlDocumentInstance.SelectSingleNode("/nc:configuration")
>
> On the other hand
> yourXmlDocumentInstance.DocumentElement
> gives you the root element without using XPath.
>
> --
>
> Martin Honnen --- MVP XML
>
http://JavaScript.FAQTs.com/
[quoted text, click to view] David Thielen wrote:
> If I have the xml:
> <?xml version="1.0"?>
> <configuration xmlns="
http://schemas.microsoft.com/.NetConfiguration/v2.0">
> ...
>
> What is the xpath in XmlDocument.SelectNodes() to get the root node? I
> thought it was "/configuration" as the namespace is the default - but that
> does not work.
Choose a prefix for your elements e.g. nc, then use an XmlNamespaceManager
XmlNamespaceManager namespaceManager = new
XmlNamespaceManager(yourXmlDocumentInstance.NameTable);
namespaceManager.AddNamespace("nc",
"
http://schemas.microsoft.com/.NetConfiguration/v2.0");
then use that prefix in your XPath expressions and pass in the namespace
manager as the second argument to SelectNodes/SelectSingleNode e.g.
yourXmlDocumentInstance.SelectSingleNode("/nc:configuration")
On the other hand
yourXmlDocumentInstance.DocumentElement
gives you the root element without using XPath.
--
Martin Honnen --- MVP XML
Hello Dave,
Thanks for Martin's suggestion.
SelectNodes() method Selects a list of nodes matching the XPath expression.
If the XPath expression does not include a prefix, SelectNodes() method is
assumed that the namespace URI is the empty namespace.(i.e. xmlns="") If
your XML includes a default namespace, we MUST use the XmlNamespaceManager
and add a prefix and namespace URI to it., just as Martin mentioned.
Otherwise, we should change the XPath expression to
XmlNodeList xnl =
yourXmlDocumentInstance.SelectNodes(@"*[local-name()='configuration']");
Or
Get the root element by the property of yourXmlDocumentInstance directly.
XmlElement configuration = yourXmlDocumentInstance.DocumentElement;
XmlElement configuration = yourXmlDocumentInstance["configuration"];
Hope this helps. Please let me know if you have any more concern. We are
glad to assist you.
Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
It's actually 3 nodes in and there can be multiple entries. So I guess I'll
try the select with the namespace and if that fails without.
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com Cubicle Wars -
http://www.windwardreports.com/film.htm [quoted text, click to view] "WenYuan Wang [MSFT]" wrote:
> Hello Dave,
> Thanks for Martin's suggestion.
>
> SelectNodes() method Selects a list of nodes matching the XPath expression.
> If the XPath expression does not include a prefix, SelectNodes() method is
> assumed that the namespace URI is the empty namespace.(i.e. xmlns="") If
> your XML includes a default namespace, we MUST use the XmlNamespaceManager
> and add a prefix and namespace URI to it., just as Martin mentioned.
>
> Otherwise, we should change the XPath expression to
> XmlNodeList xnl =
> yourXmlDocumentInstance.SelectNodes(@"*[local-name()='configuration']");
> Or
> Get the root element by the property of yourXmlDocumentInstance directly.
> XmlElement configuration = yourXmlDocumentInstance.DocumentElement;
> XmlElement configuration = yourXmlDocumentInstance["configuration"];
>
> Hope this helps. Please let me know if you have any more concern. We are
> glad to assist you.
> Have a great day,
> Sincerely,
> Wen Yuan
> Microsoft Online Community Support
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
Hello Dave,
For multiple entries, have you tried with Xpath
"*[local-name()='configuration']" ?
* will match all the namespace.
This method should work fine with/without namespace.
XmlNodeList xnl =
yourXmlDocumentInstance.SelectNodes(@"*@"*[local-name()='configuration']/*[l
ocal-name()='test']"");
Hope this helps.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
great idea - will do.
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com Cubicle Wars -
http://www.windwardreports.com/film.htm [quoted text, click to view] "WenYuan Wang [MSFT]" wrote:
> Hello Dave,
>
> For multiple entries, have you tried with Xpath
> "*[local-name()='configuration']" ?
> * will match all the namespace.
> This method should work fine with/without namespace.
>
> XmlNodeList xnl =
> yourXmlDocumentInstance.SelectNodes(@"*@"*[local-name()='configuration']/*[l
> ocal-name()='test']"");
>
> Hope this helps.
> Sincerely,
> Wen Yuan
> Microsoft Online Community Support
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
Don't see what you're looking for? Try a search.