RE: Problems Reading XML File

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
>
>
>
.



Relevant Pages

  • Re: Getting to the root node of an xml document
    ... I have some old code around here that reads and then prints out an XML file. ... It's handy because it lets you see the whole structure of the XML file; I think the root node of the tree structure isn't the root node of the document itself. ... public EditorJFrame(String filename) ... private void preOrderXml(org.w3c.dom.Node docNode, DefaultMutableTreeNode treeNode, int level) ...
    (comp.lang.java.help)
  • Re: BizTalk 2004 :: merging a multiple root node message as output
    ... If you really have a legacy system that is not using well-formed xml (or ... > I have a typical xml message as input (single root node) and I need to map ... > to a message which contains multiple root nodes. ...
    (microsoft.public.biztalk.general)
  • Re: Extract Strings
    ... Keep in mind it's not well-formed XML (needs a root node), ... XPath query on it, you can iterate the nodes like this: ... > Ok, well this isn't an ordinary string, its the string representation of ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: multiple root nodes
    ... you can't have multiple root nodes in an XML document. ... > everytime I want to do that I either get an error or the first root node ... > textData = xmldoc.createTextNodefilesInDirectory ...
    (comp.lang.java.help)
  • persist xml in class referenced in asp.net page
    ... hello I am putting together a web form which builds an xml file. ... my separate class file ie, Create root node, add elements, add ... but I would rather persist an xmldocument object in the ...
    (microsoft.public.dotnet.framework.aspnet)