Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Xml, am I missing something daft?

Status
Not open for further replies.

luigivampa

Programmer
Jul 23, 2007
2
GB
I've been having a nightmare trying to load an xml document. If anybody could help me with it it would be outstanding.

I have commented out most of the relevant code trying to isolate the fault but I'm getting to the point now that I haven't got much code left.
This is the method I'm calling :
Code:
        private void loadCategories()
        {
            try
            {
                if (File.Exists(@"d:\eRdr files\eRdr System Files\eRdr Categories.xml"))
                {
                    XmlDocument xmlCategories = new XmlDocument();
                    xmlCategories.LoadXml(@"d:\eRdr files\eRdr System Files\eRdr Categories.xml");

           //       XmlNodeList xmlndCategory = xmlCategories.SelectNodes("categories/main/category");

           //       foreach (XmlNode node in xmlndCategory)
           //      {
           //           comboBoxCategories.Items.Add(node.InnerText);
           //       }
                }
                else
                {
                    MessageBox.Show("The file at 'd:\\eRdr files\\eRdr System Files\\eRdr Categories.xml'\n cannot be found.", "Error finding file");
                }
            }
            catch (Exception ex)
            { 
                 MessageBox.Show(ex.ToString(),"Error loading file");
            }
        }

Debugging throws the exception at line 'xmlCategories.LoadXml(@"d:\eRdr files\eRdr System Files\eRdr Categories.xml");'

'Data at the root level is invalid' is the exceptions message.

The filepath is right (copied and pasted it from the folder properties!) and the xml document has been stripped down that far that it's barely a template anymore so I don't think that's the issue, here it is anyway :

Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE categories [
	<!ELEMENT categories (main)>
	<!ELEMENT main       (category,address)+>
	<!ELEMENT category   (#PCDATA)>
	<!ELEMENT address    (#PCDATA)>

]>
<categories>
	<main>
		<category>One</category>
		<address>[URL unfurl="true"]http://</address>[/URL]
		<category>Two</category>
		<address>[URL unfurl="true"]http://</address>[/URL]
		<category>Three</category>
		<address>[URL unfurl="true"]http://</address>[/URL]
		<category>Four</category>
		<address>[URL unfurl="true"]http://</address>[/URL]
	</main>
</categories>

I have even added a few extra namespaces like System.Xml.Xpath but I don't think that is even needed to read to a node,
not sure, new to xml. Again if anyone could help it would be outstanding. Thanks. LV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top