Hi.
I have xml files that look like
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1">
<asmv1:assemblyIdentity name="ClickOnceAppTest.exe" version="1.0.0.4" publicKeyToken="d1e81ecbb61bc9b1" language="neutral" processorArchitecture="x86" type="win32" />
<application />
<entryPoint>
<assemblyIdentity name="ClickOnceAppTest" version="1.0.0.1" language="neutral" processorArchitecture="x86" />
<commandLine file="ClickOnceAppTest.exe" parameters="" />
</entryPoint>
<trustInfo>
<security>
<applicationRequestMinimum>
and so on.
I need to parse it, by extracting certain tags that match by criteria (tagname, attributes).
So far I found 2 methods to search by criteria:
1.LINQ on XDocument
2.XmlDocument's SelectNodes method using XPath.
In either case I can't do that because I don't quite understand namespacing. When I try to read xml with XDocument, it prepends some asmv2: stuff to inner xml nodes. For example, in source I have
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="ClickOnceAppTest.exe" size="26112">
<assemblyIdentity name="ClickOnceAppTest" version="1.0.0.1" language="neutral" processorArchitecture="x86" />
but XDocument prepends asmv1 yielding <asmv1:dependency xmlns:asmv1="#unknown"> and so xDoc.Descendants("dependency") yields nothing.
With XPath I get saame no results situation. I've tried to write
XmlNamespaceManager mngr = new XmlNamespaceManager(serverXml.NameTable);
string xPath="assembly/dependency/dependentAssembly/";
XmlNodeList emptySet = serverXml.SelectNodes(xPath, mngr);
So, how do I tackle the problem with namespaces?
P.S. Sorry for such a cumbersome style - my moral is down by learning that I am no good at some elementary stuff.