473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

VC++ .NET 2003: XmlValidatingReader via DTD - Unknown node type

SHC
Hi all,
I created an application from the Console Application (.NET) of VC++ .NET
2003, and I did "Build" the application of the attached .cpp file,
volcanoes.xml and geology.dtd on my VC++ .NET 2003 - Windows XP Pro PC
suscessfully. But when I ran it from the command line - C:\Documents and
Settings\SHC\My Documents\Visual Studio
Projects\XMLdtdValidatingReader\Debug>XMLdtdValida tingReader valcanoes.xml,
I got the following message in the console output:
-> XML declaration
** Unknown node type
-> Comment node, name=, value= Volcano data
-> Element node, name=geology
..................................................
Please help and tell me why I have "Unknown node type" after XML declaration
and how to correct it.

Thanks in advance,
SHC

////-----XmlValidatingReader.cpp----/////
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#using <System.xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

// Validation handler class
__gc class ValHandler
{
public:
static void ValidationHandler(Object* pSender,
ValidationEventArgs* pe)
{
Console::WriteLine(S"Validation Event: {0}", pe->Message);
}
};

int _tmain(int argc, char* argv[])
{
// Check for required arguments
if (argc < 2)
{
Console::WriteLine(S"Usage: CppXmlTextReader path");
return -1;
}

String* path = new String(argv[1]);

try
{
// Create the reader...
XmlTextReader* rvr = new XmlTextReader("volcanoes.xml");

// Create the validating reader and set the validation type
XmlValidatingReader* xvr = new XmlValidatingReader(rvr);
xvr->ValidationType = ValidationType::Auto;

// Set the handler
xvr->ValidationEventHandler +=
new ValidationEventHandler(0, &ValHandler::ValidationHandler);

// Read nodes from the XmlValidatingReader
while (xvr->Read())
{
switch (xvr->NodeType)
{
case XmlNodeType::XmlDeclaration:
Console::WriteLine(S"-> XML declaration");
break;
case XmlNodeType::Document:
Console::WriteLine(S"-> Document node");
break;
case XmlNodeType::Element:
Console::WriteLine(S"-> Element node, name={0}", xvr->Name);
break;
case XmlNodeType::EndElement:
Console::WriteLine(S"-> End element node, name={0}",
xvr->Name);
break;
case XmlNodeType::Text:
Console::WriteLine(S"-> Text node, value={0}", xvr->Value);
break;
case XmlNodeType::Comment:
Console::WriteLine(S"-> Comment node, name={0}, value={1}",
xvr->Name, xvr->Value);
break;
case XmlNodeType::Whitespace:
break;
default:
Console::WriteLine(S"** Unknown node type");
break;
}
}
}
catch (Exception* pe)
{
Console::WriteLine(pe->ToString());
}

return 0;
}

/////----volcanoes.xml----/////
<?xml version="1.0" ?>
<!DOCTYPE geology SYSTEM "geology.dtd">
<!-- Volcano data -->
<geology>
<volcano name="Erebus">
<location>Ross Island, Antarctica</location>
<height value="3794" unit="m"/>
<type>stratovolcano</type>
<eruption>constant activity</eruption>
<magma>basanite to trachyte</magma>
</volcano>
<volcano name="Hekla">
<location>Iceland</location>
<type>stratovolcano</type>
<height value="1491" unit="m"/>
<eruption>1970</eruption>
<eruption>1980</eruption>
<eruption>1991</eruption>
<magma>calcalkaline</magma>
<comment>The type is actually intermediate between crater row
and stratovolcano types</comment>
</volcano>
<volcano name="Mauna Loa">
<location>Hawaii</location>
<type>shield</type>
<height value="13677" unit="ft"/>
<eruption>1984</eruption>
<magma>basaltic</magma>
</volcano>
</geology>

/////---geology.dtd----/////
<!ELEMENT geology (volcano)+>
<!ELEMENT volcano (location, height, type, eruption+, magma, comment?>
<!ELEMENT volcano name CDATA #IMPLIED>
<!ELEMENT location (#PCDATA)>
<!ELEMENT height EMPTY>
<!ELEMENT height value CDATA #IMPLIED
unit CDATA #IMPLIED)
<!ELEMENT type (#PCDATA)>
<!ELEMENT eruption (#PCDATA)>
<!ELEMENT magma (#PCDATA)>
<!ELEMENT comment (#PCDATA)>
Nov 12 '05 #1
6 2711


SHC wrote:

<?xml version="1.0" ?>
<!DOCTYPE geology SYSTEM "geology.dtd">
<!-- Volcano data -->
<geology>
<volcano name="Erebus">
<location>Ross Island, Antarctica</location>
<height value="3794" unit="m"/>
<type>stratovolcano</type>
<eruption>constant activity</eruption>
<magma>basanite to trachyte</magma>
</volcano>
<volcano name="Hekla">
<location>Iceland</location>
<type>stratovolcano</type>
<height value="1491" unit="m"/>
<eruption>1970</eruption>
<eruption>1980</eruption>
<eruption>1991</eruption>
<magma>calcalkaline</magma>
<comment>The type is actually intermediate between crater row
and stratovolcano types</comment>
</volcano>
<volcano name="Mauna Loa">
<location>Hawaii</location>
<type>shield</type>
<height value="13677" unit="ft"/>
<eruption>1984</eruption>
<magma>basaltic</magma>
</volcano>
</geology>

/////---geology.dtd----/////
<!ELEMENT geology (volcano)+>
<!ELEMENT volcano (location, height, type, eruption+, magma, comment?>
<!ELEMENT volcano name CDATA #IMPLIED>
You probably want
<!ATTLIST volcano
name CDATA #IMPLIED>
here and
<!ELEMENT location (#PCDATA)>
<!ELEMENT height EMPTY>
<!ELEMENT height value CDATA #IMPLIED
unit CDATA #IMPLIED)


<!ATTLIST height
value CDATA #IMPLIED
unit CDATA #IMPLIED>

and so on the declare the attributes of the elements you have.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
SHC
Thanks, Martin.

I used someone's volcanoes.xml and geology.dtd in my XmlValidatingReader
project. I had a hard time to open the geology.dtd file. How can I open the
..dtd file and edit it? Please help and respond.

Thanks again,
SHC
Nov 12 '05 #3


SHC wrote:
I had a hard time to open the geology.dtd file. How can I open the
.dtd file and edit it?


You can certainly edit a DTD file with a text editor like notepad. I am
not sure how good Visual Studio is at editing DTD files.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
SHC
Hello Martin, Thanks for your response.

I changed the extension of geology.dtd to 'txt' and then opened the file in
my 'Notepad' program. I found that the actual coding in the geology.dtd had
your suggested code statements. The source code I stated in my first post was
what I copied from a XML book. Now I feel that the error of "Unknown node
type" appeared in my XmlValidatingReader project is not resolved. Please
re-examine my "Unknown node type" problem and tell me what is wrong with my
coding in XmlValidatingReader.cpp, or volcanoes.xml, or geology.dtd.

Many Thanks,
SHC
Nov 12 '05 #5
What is the integer value of xvr->NodeType and does it map to any of the
following?

public enum XmlNodeType {
// Summary:
// This is returned by the System.Xml.XmlReader if a Read method has
not been
// called.
None = 0,
//
// Summary:
// An element (for example, <item> ).
Element = 1,
//
// Summary:
// An attribute (for example, id='123' ).
Attribute = 2,
//
// Summary:
// The text content of a node.
Text = 3,
//
// Summary:
// A CDATA section (for example, <![CDATA[my escaped text]]> ).
CDATA = 4,
//
// Summary:
// A reference to an entity (for example, &num; ).
EntityReference = 5,
//
// Summary:
// An entity declaration (for example, <!ENTITY...> ).
Entity = 6,
//
// Summary:
// A processing instruction (for example, <?pi test?> ).
ProcessingInstruction = 7,
//
// Summary:
// A comment (for example, <!-- my comment --> ).
Comment = 8,
//
// Summary:
// A document object that, as the root of the document tree,
provides access to
// the entire XML document.
Document = 9,
//
// Summary:
// The document type declaration, indicated by the following tag
(for example,
// <!DOCTYPE...> ).
DocumentType = 10,
//
// Summary:
// A document fragment.
DocumentFragment = 11,
//
// Summary:
// A notation in the document type declaration (for example,
<!NOTATION...> ).
Notation = 12,
//
// Summary:
// White space between markup.
Whitespace = 13,
//
// Summary:
// White space between markup in a mixed content model or white
space within
// the xml:space="preserve" scope.
SignificantWhitespace = 14,
//
// Summary:
// An end element tag (for example, </item> ).
EndElement = 15,
//
// Summary:
// Returned when XmlReader gets to the end of the entity replacement
as a
// result of a call to System.Xml.XmlReader.ResolveEntity().
EndEntity = 16,
//
// Summary:
// The XML declaration (for example, <?xml version='1.0'?> ).
XmlDeclaration = 17,
}

"SHC" <SH*@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Hi all,
I created an application from the Console Application (.NET) of VC++ .NET
2003, and I did "Build" the application of the attached .cpp file,
volcanoes.xml and geology.dtd on my VC++ .NET 2003 - Windows XP Pro PC
suscessfully. But when I ran it from the command line - C:\Documents and
Settings\SHC\My Documents\Visual Studio
Projects\XMLdtdValidatingReader\Debug>XMLdtdValida tingReader
valcanoes.xml,
I got the following message in the console output:
-> XML declaration
** Unknown node type
-> Comment node, name=, value= Volcano data
-> Element node, name=geology
..................................................
Please help and tell me why I have "Unknown node type" after XML
declaration
and how to correct it.

Thanks in advance,
SHC

////-----XmlValidatingReader.cpp----/////
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#using <System.xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

// Validation handler class
__gc class ValHandler
{
public:
static void ValidationHandler(Object* pSender,
ValidationEventArgs* pe)
{
Console::WriteLine(S"Validation Event: {0}", pe->Message);
}
};

int _tmain(int argc, char* argv[])
{
// Check for required arguments
if (argc < 2)
{
Console::WriteLine(S"Usage: CppXmlTextReader path");
return -1;
}

String* path = new String(argv[1]);

try
{
// Create the reader...
XmlTextReader* rvr = new XmlTextReader("volcanoes.xml");

// Create the validating reader and set the validation type
XmlValidatingReader* xvr = new XmlValidatingReader(rvr);
xvr->ValidationType = ValidationType::Auto;

// Set the handler
xvr->ValidationEventHandler +=
new ValidationEventHandler(0, &ValHandler::ValidationHandler);

// Read nodes from the XmlValidatingReader
while (xvr->Read())
{
switch (xvr->NodeType)
{
case XmlNodeType::XmlDeclaration:
Console::WriteLine(S"-> XML declaration");
break;
case XmlNodeType::Document:
Console::WriteLine(S"-> Document node");
break;
case XmlNodeType::Element:
Console::WriteLine(S"-> Element node, name={0}", xvr->Name);
break;
case XmlNodeType::EndElement:
Console::WriteLine(S"-> End element node, name={0}",
xvr->Name);
break;
case XmlNodeType::Text:
Console::WriteLine(S"-> Text node, value={0}", xvr->Value);
break;
case XmlNodeType::Comment:
Console::WriteLine(S"-> Comment node, name={0}, value={1}",
xvr->Name, xvr->Value);
break;
case XmlNodeType::Whitespace:
break;
default:
Console::WriteLine(S"** Unknown node type");
break;
}
}
}
catch (Exception* pe)
{
Console::WriteLine(pe->ToString());
}

return 0;
}

/////----volcanoes.xml----/////
<?xml version="1.0" ?>
<!DOCTYPE geology SYSTEM "geology.dtd">
<!-- Volcano data -->
<geology>
<volcano name="Erebus">
<location>Ross Island, Antarctica</location>
<height value="3794" unit="m"/>
<type>stratovolcano</type>
<eruption>constant activity</eruption>
<magma>basanite to trachyte</magma>
</volcano>
<volcano name="Hekla">
<location>Iceland</location>
<type>stratovolcano</type>
<height value="1491" unit="m"/>
<eruption>1970</eruption>
<eruption>1980</eruption>
<eruption>1991</eruption>
<magma>calcalkaline</magma>
<comment>The type is actually intermediate between crater row
and stratovolcano types</comment>
</volcano>
<volcano name="Mauna Loa">
<location>Hawaii</location>
<type>shield</type>
<height value="13677" unit="ft"/>
<eruption>1984</eruption>
<magma>basaltic</magma>
</volcano>
</geology>

/////---geology.dtd----/////
<!ELEMENT geology (volcano)+>
<!ELEMENT volcano (location, height, type, eruption+, magma, comment?>
<!ELEMENT volcano name CDATA #IMPLIED>
<!ELEMENT location (#PCDATA)>
<!ELEMENT height EMPTY>
<!ELEMENT height value CDATA #IMPLIED
unit CDATA #IMPLIED)
<!ELEMENT type (#PCDATA)>
<!ELEMENT eruption (#PCDATA)>
<!ELEMENT magma (#PCDATA)>
<!ELEMENT comment (#PCDATA)>

Nov 12 '05 #6
SHC
Hi Chris, Thanks for your response.

The question you asked is above my head and I do not know the answer for it
and I have no ideas what the "map" is. Please tell me what causes the
"Unknown node type" in the XmlValidatingReader.cpp. The "Unknown node type"
happens in my XmlTextReader.cpp before too. Please help and respond.

Thanks,
SHC
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alejandro Calbazana | last post by:
Hello, Should the XmlValidatingReader validating xml against an xsd serially (e.g. - does the XML have to be in the correct position in order for a document to be valid)? For example, I am...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
9
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as...
3
by: jason | last post by:
i am using an XMLValidatingReader in a manner similar to the following code example: string sReturn = ""; XmlValidatingReader oXML = new XmlValidatingReader(sXMLString, XmlNodeType.Document,...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
1
by: Bernhard Felkel | last post by:
I have troubles validating XML files with key/keyref constraints. Here´s my schema: <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
5
by: Sergey Poberezovskiy | last post by:
Hi, I have an .xsd document (Inc_B.xsd) that "includes" two more from the same folder: <xs:include schemaLocation="Inc.xsd" /> <xs:include schemaLocation="Inc_A.xsd" /> They all have the same...
9
by: Stuart Carnie | last post by:
Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLib> as an element of a std::list, as follows...
1
by: rampm2007 | last post by:
Hi, I am using the XmlTextReader along XmlValidatingReader for parsing the XML file. Becuase of the foreign characters sometimes I get the "There is an invalid character in the given encoding"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.