473,324 Members | 2,370 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,324 software developers and data experts.

getNodeType() function not working Properly

Hi all,

I had downloaded the Xerces C++ DOMLibrary and had also prepared a
parser which reads a file which is similar to our Menu.
Now in the similarway iam trying to prepare a parser for one more
Schema which is as follows:

<ConfigurationFile Name="EventConfiguration"
Id="ID_EVENTCONFIGURATION">
<Events Name="MouseEvents" Id="ID_MOUSEEVENTS">
<Event Name="LCDOWN" Id="ID_LCDOWN">
<Mode Name="Select" Id="ID_SELECT">
<Command>LCDOWN Selected</Command>
</Mode>
</Event>
<Event Name="LCUP" Id="ID_LCUP">
<Mode Name="Move" Id="ID_MOVE">
<Command>LCUP Moved</Command>
</Mode>
</Event>
<Event Name="LDCUP" Id="ID_LDCUP">
<Mode Name="Add" Id="ID_ADD">
<Command>LDCUP Added</Command>
</Mode>
</Event>
</Events>
<Events Name="KeyBoardEvents" Id="ID_KEYBOARDEVENTS">
<Event Name="ENTER" Id="ID_ENTER">
<Mode Name="Select" Id="ID_SELECT">
<Command>Selected ENTER</Command>
</Mode>
</Event>
<Event Name="Delete" Id="ID_DELETE">
<Mode Name="Select" Id="ID_SELECT">
<Command>Selected Delete</Command>
</Mode>
</Event>
<Event Name="Back" Id="ID_BACK">
<Mode Name="Select" Id="ID_SELECT">
<Command>Selected Back</Command>
</Mode>
</Event>
</Events>
</ConfigurationFile>

For the above schema iam writing a parser but when i come to the MODE
tag,if i try to check the condition pDOMNode->getNodeType();
it returns a value 3 even it is an element Node.
if i donot check the condition it gives me a #text value followed by
the correct value int he nxt iteration.
Can any one suggest me whay is this happening?
U can see the whole code and class which i had written.
main.cpp

#include "XMLFileParser.h"

#include <iostream>
using namespace std;

void main()
{
XMLFileParser fileParser;
bool bIsParsed = false;
bIsParsed = fileParser.OpenXMLDocument("Event.xml");

if (bIsParsed)
{
std::cout<<"Successfully read the XML Document";
}
else
{
std::cout<<"Error reading the XML Document";
}

getchar();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
XMLFileParser.cpp

#include "XMLFileParser.h"

XMLFileParser::XMLFileParser()
{
m_pDOMParser = 0;
m_pXMLDocument = 0;
m_pToolBarData = 0;
m_pMenuParentData = 0;
m_pMouseEventData = 0;
m_pKeyBoardEventData = 0;
}

XMLFileParser::~XMLFileParser()
{
// Delete the m_pDOMParser itself.
if (m_pDOMParser != 0)
{
m_pDOMParser->release();
}

// Call the termination method
XMLPlatformUtils::Terminate();

}

int XMLFileParser::Initialize()
{
bool bReturn = false;
DOMImplementation* pDOMImpl = 0;
char localeStr[64] = {0};

memset(localeStr, 0, sizeof localeStr);
XMLPlatformUtils::Initialize(localeStr);

pDOMImpl = DOMImplementationRegistry::getDOMImplementation(NU LL);
if (pDOMImpl != 0)
{
m_pDOMParser =
((DOMImplementationLS*)pDOMImpl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHR ONOUS,
0);

if (m_pDOMParser != 0)
{
// Instantiate the DOM m_pDOMParser.
m_pDOMParser->setFeature(XMLUni::fgDOMNamespaces, true);
m_pDOMParser->setFeature(XMLUni::fgXercesSchema, true);
m_pDOMParser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
m_pDOMParser->setFeature(XMLUni::fgDOMValidateIfSchema, true);
m_pDOMParser->setFeature(XMLUni::fgDOMValidation, true);
m_pDOMParser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);

bReturn = true;
}
}

return bReturn;
}

void XMLFileParser::ReadConfigurationFile(const DOMNode *pDOMNode)
{
char *strTag = 0;

short count = pDOMNode->getNodeType();
cout<<count;
if ((pDOMNode) &&(pDOMNode->getNodeType() == DOMNode::ELEMENT_NODE) &&
(pDOMNode->hasChildNodes()))
{

//get the tag Name
strTag = XMLString::transcode(pDOMNode->getNodeName());
//std::cout<<strTag<<endl;

if (strcmpi(strTag, "ConfigurationFile") == 0)
{
XMLString::release(&strTag);
vector<ATTRIBUTE> vecConfigurationAttr;

GetNodeAttributes(pDOMNode, vecConfigurationAttr);
cout<<"vecConfigurationAttrsize ="<<vecConfigurationAttr.size();
for(unsigned int i=0;i<vecConfigurationAttr.size();i++)
{
cout<<vecConfigurationAttr[i].strVal.c_str()<<endl;
}

if (vecConfigurationAttr.size() > 0)
{
if (vecConfigurationAttr[0].strVal.compare("ToolBarsandMenu") == 0)

{
//GetToolBarsandMenuElements(pDOMNode);
}
else if
(vecConfigurationAttr[1].strVal.compare("EventConfiguration") == 0)
{
cout<<vecConfigurationAttr[1].strVal.c_str()<<endl;
GetEventConfigurationElements(pDOMNode);
}
}
//cout<<vecConfigurationAttr[1].strVal<<endl;
}
}
}

void XMLFileParser::GetEventConfigurationElements(const DOMNode
*pDOMNode)
{
char *strTag = 0;
MAPEVENT* pMapEvent = 0;
//vector<ATTRIBUTE> vecEventsAttr;

short count = pDOMNode->getNodeType();
cout<<count;
if ((pDOMNode) &&(pDOMNode->getNodeType() == DOMNode::ELEMENT_NODE) &&
(pDOMNode->hasChildNodes()))
{
for(DOMNode *pChildNode = pDOMNode->getFirstChild(); pChildNode != 0;
pChildNode = pChildNode->getNextSibling())
{
short count = pDOMNode->getNodeType();
cout<<count;
if ((pChildNode) &&(pChildNode->getNodeType() ==
DOMNode::ELEMENT_NODE) && (pChildNode->hasChildNodes()))
{
strTag = XMLString::transcode(pChildNode->getNodeName());
vector<ATTRIBUTE> vecEventsAttr;

GetNodeAttributes(pChildNode, vecEventsAttr);

cout<<vecEventsAttr[1].strVal.c_str()<<endl;
if(strcmpi(strTag, "Events") == 0)
{
if (vecEventsAttr[1].strVal.compare("MouseEvents") == 0)
{
m_pMouseEventData = new MAPEVENT();
pMapEvent = m_pMouseEventData;
}
else if (vecEventsAttr[1].strVal.compare("KeyBoardEvents") == 0)
{
m_pKeyBoardEventData = new MAPEVENT();
pMapEvent = m_pKeyBoardEventData;
}

GetEventElements(pChildNode, pMapEvent);
}
}
}
}
}

void XMLFileParser::GetEventElements(const DOMNode *pDOMNode,
MAPEVENT*& pMapEvent)
{
char *strTag = 0;

if ((pDOMNode) && (pDOMNode->getNodeType() == DOMNode::ELEMENT_NODE)
&& (pDOMNode->hasChildNodes()))
{
short count = pDOMNode->getNodeType();
cout<<count;
for (DOMNode *pChildNode = pDOMNode->getFirstChild(); pChildNode !=
0; pChildNode = pChildNode->getNextSibling())
{
MAPEVENT mapMouseEvent,mapKeyBoardEvent;

short count = pDOMNode->getNodeType();
cout<<count;
if ((pChildNode) && (pChildNode->getNodeType() ==
DOMNode::ELEMENT_NODE) && (pChildNode->hasChildNodes()))
{
strTag = XMLString::transcode(pChildNode->getNodeName());
short count = pChildNode->getNodeType();
cout<<count;

if (strcmpi(strTag, "Event") == 0)
{
MAPMODE* pMapMode = new MAPMODE;
vector<ATTRIBUTE> vecEventAttr;
GetNodeAttributes(pChildNode, vecEventAttr);

cout<<vecEventAttr[0].strVal.c_str()<<endl;
(*pMapEvent)[vecEventAttr[0].strVal] = pMapMode;

DOMNode *pGrandChildNode = pChildNode->getFirstChild();
strTag = XMLString::transcode(pGrandChildNode->getNodeName());
short count = pGrandChildNode->getNodeType();
cout<<count;
GetModeElements(pGrandChildNode, pMapMode);
}
}
}
}
}

void XMLFileParser::GetModeElements(const DOMNode *pDOMNode, MAPMODE*&
pMapTempMode)
{
char *strTag = 0;

short count = pDOMNode->getNodeType();
cout<<count;
if ((pDOMNode) &&(pDOMNode->getNodeType() == DOMNode::TEXT_NODE) &&
(pDOMNode->hasChildNodes()))
{
strTag = XMLString::transcode(pDOMNode->getNodeName());
//cout<<strTag<<endl;

if (strcmpi(strTag, "Mode") == 0)
{
vector<ATTRIBUTE> vecModeAttr;
GetNodeAttributes(pDOMNode, vecModeAttr);

DOMNode *pChildNode = pDOMNode->getFirstChild();
if ((pChildNode) && (pChildNode->getNodeType() ==
DOMNode::ELEMENT_NODE))
{
strTag = XMLString::transcode(pChildNode->getNodeName());
cout<<strTag<<endl;

if (strcmpi(strTag, "Command") == 0)
{
vector<ATTRIBUTE> vecCommandAttr;
GetNodeAttributes(pChildNode, vecCommandAttr);
cout<<vecModeAttr[1].strVal.c_str()<<endl;
cout<<vecCommandAttr[1].strVal.c_str()<<endl;
(*pMapTempMode)[vecModeAttr[1].strVal.c_str()] =
vecCommandAttr[1].strVal.c_str();
}
}
}
pDOMNode = pDOMNode->getNextSibling();
GetModeElements(pDOMNode, pMapTempMode);
}
}

//Retrieves all the Attributes for a ParticularNode
void XMLFileParser::GetNodeAttributes(const DOMNode *pDOMNode,
std::vector<ATTRIBUTE>& vecAttr)
{

if(pDOMNode->hasAttributes()) //Check whether that node has
attributes or not
{
ATTRIBUTE Attr;
DOMAttr* pAttributeNode = 0;

// Retrieve all the attributes of the node
DOMNamedNodeMap *pAttributes = pDOMNode->getAttributes();

for(unsigned int i = 0; i < pAttributes->getLength(); i++)
{
pAttributeNode = (DOMAttr*) pAttributes->item(i);

// Retrieve the attribute name
Attr.strName.assign(XMLString::transcode(pAttribut eNode->getName()));

// Retrieve the attribute type
Attr.strVal.assign(XMLString::transcode(pAttribute Node->getValue()));

vecAttr.push_back(Attr); //Push all the attributes in a vector
}
}
}

/*void XMLFileParser::DisplayEventData(EVENTDATA pEventData)
{
if(pEventData !=0)
{
pEventData::iterator p;
for(itm = mapMouseEvent.begin();itm != mapMouseEvent.end();itm++)
{
cout<<itm->first;
for(p =(itm->second).begin();p !=(itm->second).end();itm++)
{
cout<<p->first<<endl<<p->second;
}
}
}
}*/

bool XMLFileParser::OpenXMLDocument(const char* strFileName)
{
bool bReturn = true;
// reset document pool

try
{
if (Initialize())
{
m_pDOMParser->resetDocumentPool();
m_pXMLDocument = m_pDOMParser->parseURI(strFileName);

// Extract the DOM tree, get the list of all the elements

if (m_pXMLDocument)
{
ReadConfigurationFile((DOMNode*)m_pXMLDocument->getDocumentElement());
//DisplayMenuData(m_pMenuParentData);
//DisplayToolbarsData(m_pToolBarData);
//DisplayEventData(m_pMouseEventData);
//DisplayEventData(m_pKeyBoardEventData);
bReturn = true;
}
}
else
{
bReturn = false;
}
}
catch (...)
{
bReturn = false;
}

return bReturn;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
XMLFileParser.h

#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/parsers/AbstractDOMParser.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMImplementationLS.hpp>
#include <xercesc/dom/DOMImplementationRegistry.hpp>
#include <xercesc/dom/DOMBuilder.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNodeList.hpp>
#include <xercesc/dom/DOMError.hpp>
#include <xercesc/dom/DOMLocator.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/dom/DOMErrorHandler.hpp>
#include <xercesc/util/XMLString.hpp>

#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif
XERCES_CPP_NAMESPACE_USE

#include <vector>
#include <string>
#include <map>
using namespace std;

typedef struct
{
string strName;
string strVal;
} ATTRIBUTE;
typedef struct
{
string strDisplayName;
string strId;
string strType;

} ATTRIBUTEDATA;

typedef struct MENUDATA
{
ATTRIBUTEDATA structAttribData;
vector<MENUDATA*> vecMenuData;
} MENUDATA;

typedef struct
{
std::vector<ATTRIBUTEDATA*> vecDrawingToolBar;
std::vector<ATTRIBUTEDATA*> vecTextToolBar;
std::vector<ATTRIBUTEDATA*> vecRunTimeOptionsToolBar;
std::vector<ATTRIBUTEDATA*> vecFileControlToolBar;
std::vector<ATTRIBUTEDATA*> vecNodeStyleToolBar;
std::vector<ATTRIBUTEDATA*> vecAlignmentToolBar;
std::vector<ATTRIBUTEDATA*> vecStandardToolBar;
} TOOLBARDATA;

typedef map<string, string> MAPMODE;
typedef map<string, MAPMODE*> MAPEVENT;
class XMLFileParser
{
private:
MAPEVENT* m_pMouseEventData;
MAPEVENT* m_pKeyBoardEventData;
TOOLBARDATA* m_pToolBarData;
MENUDATA* m_pMenuParentData;

DOMBuilder* m_pDOMParser;
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *m_pXMLDocument;
int Initialize();
void ReadConfigurationFile(const DOMNode *pDOMNode);
//void GetToolBarsandMenuElements(const DOMNode *pDOMNode);
void GetEventConfigurationElements(const DOMNode *pDOMNode);
void GetEventElements(const DOMNode *pDOMNode, MAPEVENT*&);
void GetModeElements(const DOMNode *pDOMNode, MAPMODE*&);
void GetCommandElements(const DOMNode *pDOMNode,
std::vector<ATTRIBUTE>& vecTempCommandAttr); /*void
GetToolBarElements(const DOMNode *pDOMNode,
vector<ATTRIBUTEDATA*>& vecToolbarElements);
ATTRIBUTEDATA* GetToolElements(const DOMNode *pDOMNode);
void GetMenuElements(const DOMNode *pDOMNode, MENUDATA*
pMenuParentData,
MENUDATA* pMenuChildData);*/

void GetNodeAttributes(const DOMNode *pDOMNode,
std::vector<ATTRIBUTE>& vecAttr);

void GetTempElements(const DOMNode *pDOMNode, MAPMODE*&);
/*void GetToolBars(const DOMNode *pDOMNode);
bool CheckNode(const DOMNode *pDOMNode);
void DisplayMenuData(MENUDATA* pMenuData);
void DisplayToolbarsData(TOOLBARDATA* pToolbarData);
void DisplayEventData();
*/

public:
XMLFileParser();
~XMLFileParser();

bool OpenXMLDocument(const char* strFileName);
};
Thanking u in Advance.
Hepsiba Sushma

Mar 28 '06 #1
2 1684
You may not be looking at the node you think you're looking at. Remember
that whitespace/indentation becomes a text node...

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 28 '06 #2
Hi Joe,

I had removed all the Whitespaces and indentation but no use.
Even if i give the earlier schema which has already worked then also it
is halting at the same point.

Bye
Hepsiba Sushma

Mar 28 '06 #3

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
1
by: John | last post by:
Function that works second time I have a function that works fine, but only the second time.I mean with the first click the report is opened blank, and just when i click second time, the...
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
6
by: Notre Poubelle | last post by:
Hello, I have a strange situation where I'm trying to export a function in a class, but it won't get exported. I actually have a couple of header and cpp files. Each pair of header and cpp...
5
by: christian.eickhoff | last post by:
Hello Everybody, am currently developing some coder for XML files but am facing some minor problem which might be very easy to solve for XERCES experts. For my coder it is indispensable to...
14
by: Nickolay Ponomarev | last post by:
Hi, Why does http://www.jibbering.com/faq/ uses new Function constructor instead of function expressions (function(...) { ... }) when defining new functions? E.g. for LTrim and toFixed. Is the...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
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...
0
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
1
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.