472,782 Members | 1,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

XML Parsing Error

I am writing a program for one of my C++ classes at school and have gotten an error that I can't debug. What I am trying to do is write a C++ program that parses an XML file and displays to console all the different elements of the XML file. The error message I continuously keep getting is "Data at the root level is invalid. Line 1, Position 1." Please advise!

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #using <mscorlib.dll>
  3. #using <System.xml.dll>
  4.  
  5.  
  6.  
  7. using namespace System;
  8. using namespace System::Xml;
  9.  
  10.  
  11.  
  12.  
  13. int _tmain(int argc, _TCHAR* argv[])
  14. {
  15.  
  16.  
  17.     try
  18.   {
  19.  
  20.     //load xml file into reader
  21.     XmlTextReader*  txtreader = new XmlTextReader (argv[0]);
  22.     XmlValidatingReader*  XmlReader = new XmlValidatingReader(txtreader);
  23.  
  24.     //while still reading a line from XML file
  25.     while (XmlReader->Read())
  26.     {
  27.         switch (XmlReader->NodeType)
  28.         {
  29.  
  30.             case XmlNodeType::Element: // The node is an element.
  31.  
  32.                 Console::Write(XmlReader->Name);
  33.                 Console::Write("\t");
  34.  
  35.                 //read the next attribute of the element
  36.                 while (XmlReader->MoveToNextAttribute()) 
  37.                 Console::Write(" {0}='{1}'", XmlReader->Name, XmlReader->Value);
  38.  
  39.                 break;
  40.             case XmlNodeType::Text: //Display the text in each element.
  41.                 Console::WriteLine (XmlReader->Value);
  42.  
  43.                 break;
  44.             case XmlNodeType::EndElement: //Display the end of the element.
  45.  
  46.                 break;
  47.         }
  48.     }
  49.     Console::ReadLine();
  50.  
  51.  
  52.   }
  53.   catch (Exception *e)
  54.   {
  55.     System::Console::WriteLine("load problem");
  56.     System::Console::WriteLine(e->Message);
  57.  
  58.   }
  59.  
  60.  
  61.  
  62.   return 0;
  63. }
stdafx.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
stdafx.h
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3.  
  4. #include <iostream>
  5. #include <tchar.h>
Feb 1 '07 #1
2 1953
anyone know?
Feb 1 '07 #2
r035198x
13,262 8TB
I am writing a program for one of my C++ classes at school and have gotten an error that I can't debug. What I am trying to do is write a C++ program that parses an XML file and displays to console all the different elements of the XML file. The error message I continuously keep getting is "Data at the root level is invalid. Line 1, Position 1." Please advise!

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #using <mscorlib.dll>
  3. #using <System.xml.dll>
  4.  
  5.  
  6.  
  7. using namespace System;
  8. using namespace System::Xml;
  9.  
  10.  
  11.  
  12.  
  13. int _tmain(int argc, _TCHAR* argv[])
  14. {
  15.  
  16.  
  17.     try
  18. {
  19.  
  20.     //load xml file into reader
  21.     XmlTextReader* txtreader = new XmlTextReader (argv[0]);
  22.     XmlValidatingReader* XmlReader = new XmlValidatingReader(txtreader);
  23.  
  24.     //while still reading a line from XML file
  25. while (XmlReader->Read())
  26. {
  27. switch (XmlReader->NodeType)
  28. {
  29.  
  30.             case XmlNodeType::Element: // The node is an element.
  31.  
  32.                 Console::Write(XmlReader->Name);
  33.                 Console::Write("\t");
  34.  
  35.                 //read the next attribute of the element
  36. while (XmlReader->MoveToNextAttribute()) 
  37.                 Console::Write(" {0}='{1}'", XmlReader->Name, XmlReader->Value);
  38.  
  39. break;
  40.             case XmlNodeType::Text: //Display the text in each element.
  41.                 Console::WriteLine (XmlReader->Value);
  42.  
  43. break;
  44.             case XmlNodeType::EndElement: //Display the end of the element.
  45.  
  46. break;
  47. }
  48. }
  49. Console::ReadLine();
  50.  
  51.  
  52. }
  53. catch (Exception *e)
  54. {
  55. System::Console::WriteLine("load problem");
  56. System::Console::WriteLine(e->Message);
  57.  
  58. }
  59.  
  60.  
  61.  
  62. return 0;
  63. }
stdafx.cpp
Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
stdafx.h
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3.  
  4. #include <iostream>
  5. #include <tchar.h>
Check that the XML is well formed(Run it on a browser or something). then check that your path to the XML file is correct.
Feb 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
3
by: David Svoboda | last post by:
I have a server program that takes commands and acts on them. The server program can also take these commands from an input file or standard input (mainly for testing purposes). As such, I often...
0
by: palabat | last post by:
Hello. I'm getting this error , "XML error parsing SOAP payload : Empty Document" when I try to execute a NuSOAP client in consuming a .NET web service. The response from the web service server...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
0
by: =?Utf-8?B?VWxmIFRob3JzZW4=?= | last post by:
I use Visual Studio 2005 for a C-project using an external compiler, and came up with the idea that error parsing would be neat, i.e. enabling the functionality available for a "normal" build...
3
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude...
2
by: Felipe De Bene | last post by:
I'm having problems parsing an HTML file with the following syntax : <TABLE cellspacing=0 cellpadding=0 ALIGN=CENTER BORDER=1 width='100%'> <TH BGCOLOR='#c0c0c0' Width='3%'>User ID</TH> <TH...
1
by: hd95 | last post by:
In a perfect world my xml feed source would produce perfect xml ..that is not the case I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing. ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.