Okay, here is the code
Thanks
-Julie
DOMParser parser;
parser.setValidationScheme( DOMParser::Val_Auto );
parser.setDoNamespaces( false );
parser.setDoSchema( false );
parser.setDoValidation( true );
parser.setValidationSchemaFullChecking( false );
DOMTreeErrorReporter errReporter;
parser.setErrorHandler( &errReporter );
parser.setCreateEntityReferenceNodes( false );
parser.setToCreateXMLDeclTypeNode( true );
static const char* szMemBufId = "request";
MemBufInputSource* memBufIS = new MemBufInputSource(
(const XMLByte*)szRequest.c_str(), _tcslen(szRequest.c_str()),
szMemBufId, false );
DOMString strPath( "file:/d:/ns3-2/bin/NSAPI.dtd" );
memBufIS->setSystemId( XMLString::replicate( strPath.rawBuffer() ) );
parser.parse(*memBufIS);
delete memBufIS; // don't need it anymore
int errorCount = parser.getErrorCount();
if (errorCount > 0)
bErrorsOccurred = true;
if ( bErrorsOccurred || errReporter.getSawErrors() )
{
m_strResult = errReporter.GetErrors();
if ( m_strResult.IsEmpty() )
m_strResult = "Unknown error parsing XML request";
m_strResult = XMLError( m_strResult );
return;
}
DOM_Document doc2 = parser.getDocument();
// doc2.normalize();
DOM_NodeList nlRequests = doc2.getElementsByTagName("NSAPI");
unsigned int cRequests = nlRequests.getLength();
// length should always be one in the prototype, for simplicity
if ( cRequests > 1 )
{
m_strError = "Too many transactions for the prototype. Try just
sending one at a time";
m_strError = XMLError( m_strError );
return;
}
DOM_Node nodeNSAPI = nlRequests.item(0);
CStdString strNodeName( nodeNSAPI.getNodeName() );
if ( strNodeName != "NSAPI" ) // should always be the case
{
m_strError = "Unexpected node: " + strNodeName;
m_strError = XMLError( m_strError );
return;
}
short type = nodeNSAPI.getNodeType();
// type should be element. This can have attributes "Retrieve"
if ( type != DOM_Node::ELEMENT_NODE ) // should always be the case - dtd
checks this
{
m_strError = "Node had unexpected type. Must be an element node: "
+ strNodeName;
m_strError = XMLError( m_strError );
return;
}
// there should probably only be one, but you never know
// first node will be NSAPI
DOM_NamedNodeMap nnmAttributes = nodeNSAPI.getAttributes();
unsigned int cAttr = nnmAttributes.getLength();
if ( cAttr > 0 ) //
{
DOMString strType = "Retrieve";
DOM_Node nodeType = nnmAttributes.getNamedItem( strType );
if ( ! nodeType.isNull() )
{
nnmAttributes.removeNamedItem( strType );
if ( ! ProcessViewRequest( nodeNSAPI, m_strResult ) )
m_strResult = XMLError( m_strResult );
}
// Todo: check to see that there are no more requests in the
message, if not, report ignored warning
return;
}
DOM_NodeList nlChildRequests = nodeNSAPI.getChildNodes();//
<<-----------**** ALWAYS RETURNS 1 CHILD :( ***
unsigned int cChildRequests = nlRequests.getLength();
for ( unsigned int i = 0; i < cChildRequests; i++ )
{
DOM_Node node = nlChildRequests.item(i);
CStdString strNodeName( node.getNodeName() );
CStdString strNodeValue( node.getNodeValue() );
short type = node.getNodeType();
if ( type == DOM_Node::ELEMENT_NODE ) // should always be the case -
dtd checks this
{
DOM_NamedNodeMap attributes = node.getAttributes(); //
debugging
unsigned int len = attributes.getLength();
// debugging
}
static CStdString strLock = "Lock";
static CStdString strDomain = "Domain";
static CStdString strTopic = "Topic";
static CStdString strContr = "Contribution";
if ( strNodeName == strLock )
{
if ( ! ProcessLockRequest( nodeNSAPI, m_strResult ) )
m_strResult = XMLError( m_strResult );
// Todo: check to see that there are no more requests in the
message, if not, report ignored warning
}
if ( strNodeName == strDomain || strNodeName == strTopic ||
strNodeName == strContr )
{
if ( ! ProcessViewRequest( node, m_strResult ) )
m_strResult = XMLError( m_strResult );
}
}
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 30, 2001 2:40 PM
To: [EMAIL PROTECTED]
Cc: '[EMAIL PROTECTED]'
Subject: RE: Stripping out whitespace
>The parser tells me it only has one child - the Domain "0" child.
>Why doesn't it recognize the second child?
It might help if you showed us how you were asking the parser for that
info. It sounds more likely to be a bug in your code than in the parser,
especially given the problem you reported with the whitespace version.
(Yes, I believe Xerces-C can be told to strip
whitespace-in-element-content. But let's get the basic program working
first!)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]