By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,022 Members | 1,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,022 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a


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

P: n/a
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

P: n/a


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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.