Click here to Skip to main content
16,005,339 members
Home / Discussions / XML / XSL
   

XML / XSL

 
GeneralRe: A beginner question Pin
Phil Hobgen20-Feb-05 6:53
Phil Hobgen20-Feb-05 6:53 
GeneralRe: A beginner question Pin
RockRock20-Feb-05 19:00
RockRock20-Feb-05 19:00 
GeneralRe: A beginner question Pin
Phil Hobgen20-Feb-05 20:08
Phil Hobgen20-Feb-05 20:08 
GeneralRe: A beginner question Pin
RockRock20-Feb-05 22:33
RockRock20-Feb-05 22:33 
GeneralXMI Pin
CSharpBala18-Feb-05 5:24
CSharpBala18-Feb-05 5:24 
GeneralRe: XMI Pin
Phil Hobgen20-Feb-05 7:14
Phil Hobgen20-Feb-05 7:14 
GeneralRe: XMI Pin
CSharpBala24-Feb-05 3:24
CSharpBala24-Feb-05 3:24 
GeneralIXMLDOMSchemaCollectionPtr->add() Pin
bandonet17-Feb-05 3:46
bandonet17-Feb-05 3:46 
I tried to use DOM to do the XML validation with XSD and I used IXMLDOMSchemaCollection.

I followed the example you can find at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmproschemas.asp

but when I arrive at instruction

hr = pSchemaCache->add("",pSchemaDDoc.GetInterfacePtr());

add() always crashed on me. In fact, I tried with some of
my own XSDs, and it crashed right at add() too.

I'm listing part of my source code below, it must be something that I missed. Please help.

Thanks!



IXMLDOMDocument2Ptr pXMLDoc = NULL;
CoInitialize(NULL);
HRESULT hr;

try
{
//load the schema file
IXMLDOMDocumentPtr pSchemaDoc;
hr = pSchemaDoc.CreateInstance(__uuidof(DOMDocument30));
pSchemaDoc->async = VARIANT_FALSE;
hr = pSchemaDoc->load("C:\\Progetti\\books.xsd");
//check on the parser error
if(hr!=VARIANT_TRUE)
{
MessageBox(NULL, "Error", "", MB_OK);
return false;
}

//create schemachache
IXMLDOMSchemaCollectionPtr pSchemaCache;
hr = pSchemaCache.CreateInstance(__uuidof(XMLSchemaCache30));

//add schema to schema cache
hr = pSchemaCache->add("", pSchemaDoc.GetInterfacePtr());

// load the XML file
// ****** you need to use IXMLDOMDocument2 interface *********
IXMLDOMDocument2Ptr pXMLDoc;
hr = pXMLDoc.CreateInstance(__uuidof(DOMDocument30));
pXMLDoc->validateOnParse = VARIANT_FALSE;
pXMLDoc->async = VARIANT_FALSE;

//associate xml doc with schemacache
pXMLDoc->schemas = pSchemaCache.GetInterfacePtr();


// relative path works in debugger, modify it with absolute path
hr = pXMLDoc->load("C:\\Progetti\\XMLfile.xml");
//check on the parser error
if(hr!=VARIANT_TRUE)
{
MessageBox(NULL, "Error", "", MB_OK);
return false;
}

//call validate
IXMLDOMParseErrorPtr pError;
pError = pXMLDoc->validate();

if(pError->errorCode != S_OK)
{
MessageBox(NULL,"validate error", "",MB_OK);
_bstr_t parseError = _bstr_t("Error code: ")+ _bstr_t(pError->errorCode) +_bstr_t("\n") + _bstr_t("Reason: ")+ pError->Getreason();
MessageBox(NULL, (char*)parseError, "Parse Error",MB_OK);
return false;
}
else
MessageBox(NULL,"Validation succeeded", "Results",MB_OK);

}
catch(_com_error e)
{
MessageBox(NULL, e.ErrorMessage(), "",MB_OK);
MessageBox(NULL, e.Source(), "",MB_OK);
return false;
}

return true;

GeneralXSLT Question Pin
dotnetquery16-Feb-05 22:15
dotnetquery16-Feb-05 22:15 
GeneralRe: XSLT Question Pin
Phil Hobgen20-Feb-05 8:56
Phil Hobgen20-Feb-05 8:56 
QuestionHow do I add a DOCTYPE declaration in XML using MSXML in Visual C++? Pin
IronMike16-Feb-05 21:38
IronMike16-Feb-05 21:38 
AnswerRe: How do I add a DOCTYPE declaration in XML using MSXML in Visual C++? Pin
Phil Hobgen21-Feb-05 10:45
Phil Hobgen21-Feb-05 10:45 
GeneralProcessing Instruction Pin
johnsaxton14-Feb-05 8:53
johnsaxton14-Feb-05 8:53 
GeneralRe: Processing Instruction Pin
Phil Hobgen14-Feb-05 23:13
Phil Hobgen14-Feb-05 23:13 
GeneralRe: Processing Instruction Pin
johnsaxton15-Feb-05 3:31
johnsaxton15-Feb-05 3:31 
GeneralRe: Processing Instruction Pin
johnsaxton15-Feb-05 3:36
johnsaxton15-Feb-05 3:36 
GeneralRe: Processing Instruction Pin
Phil Hobgen15-Feb-05 4:43
Phil Hobgen15-Feb-05 4:43 
GeneralRe: Processing Instruction Pin
johnsaxton15-Feb-05 6:59
johnsaxton15-Feb-05 6:59 
GeneralHandling a local XML file Using A Server Side Web Application Pin
parv_haghy12-Feb-05 6:41
parv_haghy12-Feb-05 6:41 
GeneralRe: Handling a local XML file Using A Server Side Web Application Pin
Wilbur J. Pereira13-Feb-05 7:46
Wilbur J. Pereira13-Feb-05 7:46 
GeneralHandling a local XML file Using A Server Side Web Application Pin
Anonymous12-Feb-05 6:28
Anonymous12-Feb-05 6:28 
Generalgenerating xml file from existing schema in C# Pin
saima azeemi11-Feb-05 23:28
saima azeemi11-Feb-05 23:28 
GeneralXmlTextWriter 101 Pin
Kenny O'Dell11-Feb-05 9:12
Kenny O'Dell11-Feb-05 9:12 
GeneralRe: XmlTextWriter 101 Pin
Phil Hobgen11-Feb-05 23:33
Phil Hobgen11-Feb-05 23:33 
GeneralShow XML as excel sheet Pin
Anonymous11-Feb-05 8:10
Anonymous11-Feb-05 8:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.