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!
stdafx.cpp
stdafx.h
Code:
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.xml.dll>
using namespace System;
using namespace System::Xml;
int _tmain(int argc, _TCHAR* argv[])
{
try
{
//load xml file into reader
XmlTextReader* txtreader = new XmlTextReader (argv[0]);
XmlValidatingReader* XmlReader = new XmlValidatingReader(txtreader);
//while still reading a line from XML file
while (XmlReader->Read())
{
switch (XmlReader->NodeType)
{
case XmlNodeType::Element: // The node is an element.
Console::Write(XmlReader->Name);
Console::Write("\t");
//read the next attribute of the element
while (XmlReader->MoveToNextAttribute())
Console::Write(" {0}='{1}'", XmlReader->Name, XmlReader->Value);
break;
case XmlNodeType::Text: //Display the text in each element.
Console::WriteLine (XmlReader->Value);
break;
case XmlNodeType::EndElement: //Display the end of the element.
break;
}
}
Console::ReadLine();
}
catch (Exception *e)
{
System::Console::WriteLine("load problem");
System::Console::WriteLine(e->Message);
}
return 0;
}
Code:
#include "stdafx.h"
Code:
#pragma once #include <iostream> #include <tchar.h>
Comment