Thanks. Between your help & Martin's before you, I managed to make it work.
"KDOR" <KDOR@newsgroups.nospam> wrote in message
news:OK9eO3vGGHA.4036@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I think your problem can be solved by using an XmlNamespaceManager on your
> calls to SelectSingleNode and SelectNodes
> Even when the nodes you are searching for are in the default namespace,
> you still need a prefix, and whenever you use a prefix in an XPath
> expression, you need an XmlNamespaceManager.
> (See class XmlNamespaceManager.AddNamespace in VS help for a description)
>
> XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc .NameTable);
> // Create a namespace manager
> nsmgr.AddNamespace("default",
http://www.microsoft.com/msi/patch); //
> Add the default namespace with a prefix of "default"; could be any
> character string e.g. "aa"
>
> XmlNode xTargetProductNode =
> xRoot.SelectSingleNode("default:TargetProduct", nsmgr); // Use the
> prefix in the XPath expression and pass the namespace manager
> XmlNodeList xNodeList = xRoot.SelectNodes("default:TargetProduct",
> nsmgr); // Use the prefix in the XPath expression
> and pass the namespace manager
>
> Regards
>
>
> "John Bowman john.bowman@thermo.com>" <<Remove this before reply> wrote in
> message news:u$iHqrqGGHA.608@TK2MSFTNGP14.phx.gbl...
>> Hi All,
>>
>> I'm fairly new to XML, so I presume I'm doing something obviously dense
>> here, but here it goes. Below is an XML file that was extracted from a
>> test Windows Installer .MSP (patch) file using the
>> MsiExtractPatchXMLData() method and directly written to disk as a test.
>> On the surface, it seems to me to be valid XML since IE can load &
>> display it.
>>
>> <MsiPatch xmlns="
http://www.microsoft.com/msi/patch_applicability.xsd" >> SchemaVersion="1.0.0.0"
>> PatchGUID="{2AAC52C8-0F60-481F-852D-116CDE7EBE0D}" MinMsiVersion="3">
>> <TargetProduct MinMsiVersion="200">
>> <TargetProductCode
>> Validate="true">{C2E2F155-71DD-458A-966B-3C231CFB5E7D}</TargetProductCode>
>> <TargetVersion Validate="true" ComparisonType="LessThanOrEqual"
>> ComparisonFilter="MajorMinorUpdate">1.00.0000</TargetVersion>
>> <TargetLanguage Validate="false">1033</TargetLanguage>
>> <UpdatedLanguages>1033</UpdatedLanguages>
>> <UpgradeCode
>> Validate="true">{1C18A718-D408-4D74-B2C6-0F6A932CE841}</UpgradeCode>
>> </TargetProduct>
>>
>> <TargetProductCode>{C2E2F155-71DD-458A-966B-3C231CFB5E7D}</TargetProductCode>
>> <SequenceData>
>> <PatchFamily>C2E2F15571DD458A966B3C231CFB5E7D</PatchFamily>
>> <Sequence>0.0.17219.55500</Sequence>
>> <Attributes>0</Attributes>
>> </SequenceData>
>> </MsiPatch>
>>
>> Now that I can actually "see" the XML for testing purposes I want to
>> extract some information from it, but it always fails to get anything.
>> For example, what's funtionally wrong with the following code? It throws
>> an exception: "Object reference not set to an instance of an object."
>> when it hits the MessageBox.Show line. When I check the LocalName of
>> xRoot, it correctly shows "MsiPatch", but fails to get the
>> xTargetProductNode, or any other nodes below the root node. Using
>> SelectNodes to get an XmlNodeList doesn't work either. The only way I can
>> seem to get the info is by looping through the ChildNodes (and comparing
>> their LocalNames to the tag I'm looking for) instead of directly with a
>> simple XPath. What am I doing wrong?
>>
>> if(File.Exists(FileSpec) == true)
>> {
>> XmlDocument xDoc = new XmlDocument();
>> xDoc.Load(DEF_OUTPUT_FILENAME);
>> XmlNode xRoot = xDoc.DocumentElement;
>> XmlNode xTargetProductNode = xRoot.SelectSingleNode("TargetProduct");
>> //XmlNodeList xNodeList = xRoot.SelectNodes("TargetProduct"); ///Also
>> fails to find anything and the xNodeList.Count = 0;
>> MessageBox.Show(xTargetProductNode.LocalName);
>> }
>> else
>> {
>> MessageBox.Show("Unable to read file:" +
>> Environment.NewLine +
>> FileSpec);
>> }
>>
>>
>> Thanks in advance for the help,
>>
>> --
>> John C. Bowman
>> Software Engineer
>> Thermo Electron Scientific Instruments Div.
>> <Remove this before reply> john.bowman@thermo.com
>>
>
>