RE: Problems Reading XML File
- From: "jsh02_nova@xxxxxxxxxxx" <jsh02novahotmailcom@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 16 Jan 2006 08:31:04 -0800
John,
Where's the declaration line? You go to have '<?xml version="1.0"
encoding="UTF-8"?>' at least, on the first line of the xml file to make it
for a valid.
thx
-jsh
"John Bowman john.bowman@xxxxxxxxxx>" wrote:
> 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@xxxxxxxxxx
>
>
>
.
- Follow-Ups:
- Re: Problems Reading XML File
- From: Scott M.
- Re: Problems Reading XML File
- References:
- Problems Reading XML File
- From: John Bowman
- Problems Reading XML File
- Prev by Date: Re: XPath from String
- Next by Date: Re: Problems Reading XML File
- Previous by thread: Problems Reading XML File
- Next by thread: Re: Problems Reading XML File
- Index(es):
Relevant Pages
|