Click to See Complete Forum and Search --> : MSXML and DTD


Sinisha Ristich
August 24th, 2001, 04:08 AM
Hi,

I'm using msxml parser to load a document in DOM. The document has it's correspondent dtd which is by the way in the same directory as xml file. I have done this before in java, using SAX parser and everything was ok. Now it's working only for the documents without dtd. This is the part of my code:

CComQIPtr m_pDoc(m_pSmartXML);
if(!m_pDoc)
{
MessageBox("XML Interface not Accessible");
return 1;
}

hr = m_pDoc->put_resolveExternals(VARIANT_TRUE);
ATLASSERT(SUCCEEDED(hr));
hr = m_pDoc->put_validateOnParse(VARIANT_TRUE);
ATLASSERT(SUCCEEDED(hr));

VARIANT_BOOL bSuccess = VARIANT_FALSE;
hr = m_pDoc->load(varFileName,&bSuccess); // critical point
ATLASSERT(SUCCEEDED(hr));

if(bSuccess == VARIANT_FALSE)
{
MessageBox("Couldn't load XML!");
return 1;
}





What's wrong with it?

Best regards

Sinisha Ristich
August 24th, 2001, 04:08 AM
Hi,

I'm using msxml parser to load a document in DOM. The document has it's correspondent dtd which is by the way in the same directory as xml file. I have done this before in java, using SAX parser and everything was ok. Now it's working only for the documents without dtd. This is the part of my code:

CComQIPtr m_pDoc(m_pSmartXML);
if(!m_pDoc)
{
MessageBox("XML Interface not Accessible");
return 1;
}

hr = m_pDoc->put_resolveExternals(VARIANT_TRUE);
ATLASSERT(SUCCEEDED(hr));
hr = m_pDoc->put_validateOnParse(VARIANT_TRUE);
ATLASSERT(SUCCEEDED(hr));

VARIANT_BOOL bSuccess = VARIANT_FALSE;
hr = m_pDoc->load(varFileName,&bSuccess); // critical point
ATLASSERT(SUCCEEDED(hr));

if(bSuccess == VARIANT_FALSE)
{
MessageBox("Couldn't load XML!");
return 1;
}





What's wrong with it?

Best regards

Todd.Harvey
January 18th, 2002, 05:27 PM
I think nothing wrong, and I suppose you have long ago figured this out. I located your post only because I am having problems with VARIANT_BOOL always being false, even though my "save" operation works.

Here is my variation of your code:

CString m_strURL = "\\myPrograms\\XML\\system.xml";
_bstr_t bstrURL = m_strURL;

MSXML2::IXMLDOMDocumentPtr pDOMDoc(__uuidof(MSXML2::DOMDocument));
m_pDOMDoc = pDOMDoc;

VARIANT_BOOL varResult = m_pDOMDoc->load(_variant_t(bstrURL));

Sinisha Ristich
January 21st, 2002, 03:27 AM
Yes, you are right.

I have figured it out, long time ago, but thanks anyway. My problem was also that I was receiving always VARIANT_FALSE. But then I used the IErrorInfo interface to obtain the last error and than the miracule happened - it told me that my document was not quite consistent with DTD as it should. It seems that msxml sax parser is a bit more rigid that java sax parser. When I corrected these problems, everything was right.

Thank you again. Bye

Sinisha Ristich
January 21st, 2002, 03:27 AM
Yes, you are right.

I have figured it out, long time ago, but thanks anyway. My problem was also that I was receiving always VARIANT_FALSE. But then I used the IErrorInfo interface to obtain the last error and than the miracule happened - it told me that my document was not quite consistent with DTD as it should. It seems that msxml sax parser is a bit more rigid that java sax parser. When I corrected these problems, everything was right.

Thank you again. Bye

Todd.Harvey
January 21st, 2002, 01:19 PM
thanks Sinischa

I am having problems with the below:

_bstr_t bstrURL = m_strURL;
VARIANT_BOOL varResult = m_pDOMDoc->save(_variant_t(bstrURL));


if ( varResult == VARIANT_TRUE)
{
AfxMessageBox("Good save! Sayonara!") ;
}
else if ( varResult == VARIANT_FALSE)
{
tmpStr.Format("the configs didn't get saved %s", m_strURL.GetBuffer(0) );
AfxMessageBox( tmpStr );
}




The save is always working, but the result is always failing. There is little info on VARIANT_BOOL.