Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How Do You Create a DOCTYPE Declaration Using MSXML?

From: DavidJohns@-----------.---------.---
To: NULL
Date: 12/1/2004 5:53:00 AM
Joe,

Thanks for the correction on the vocabulary.  I am pretty new to this.  I 
have been trying exactly what you recommended, but the problem is that in C++ 
the function is requiring the refChild to be passed in as a "VARIANT".  I 
can't figure out how this VARIANT is used to point to the child I want to add 
it in front of :(.  Any ideas from you or anyone who is experienced with this 
in c++?

Thanks,
David

"Joe Fawcett" wrote:

> "David Johns" <DavidJohns@d...> wrote in message
> news:A0697489-D26E-4910-B65A-F92FFCECB830@m......
> > Joe,
> >
> > Thanks for the great idea!  I have implemented the loadXML() option that
> you
> > outlined.  I just have one other quick question.  the XML I load contains
> > just the DOCTYPE and the root node, which I then grab and add child nodes
> to.
> >  That works great, but I need to add a processing instruction to the top
> of
> > the file, but can't seem to get the syntax right for the insertBefore
> method
> > (which I assume is the proper way to do it).  How exactly do I pass the
> > refChild in?  Here is what I tried but it didn't work:
> >
> > hr = pDoc->loadXML(L"<!DOCTYPE Test SYSTEM
> > \"test.dtd\">\n<TrackingUpdate></TrackingUpdate>", &varResult);
> > if(hr!=S_OK || varResult!=VARIANT_TRUE){
> > if(pDoc->get_parseError(&pXMLErr)==S_OK){
> > if(node.Import(pXMLErr)){
> > strError.Format("Unable to build XML file.  %s.", node.text);
> > throw strError;
> > }
> > pXMLErr->Release();
> > pXMLErr=NULL;
> > }
> > strError = "Unable to build XML file.  The file may be reserved by the
> > operating system.";
> > throw strError;
> > }
> >
> > if(pDoc->get_childNodes(&pNodes)!=S_OK){
> > strError = "Unable to create root element.";
> > throw strError;
> > }
> >
> > //Create Processing Instruction
> > if(pNodes->get_item(0, &pNode)!=S_OK){
> > strError = "Unable to create root element.";
> > throw strError;
> > }
> > varPointer.vt = VT_BYREF;
> > varPointer.byref = &pNode;
> > if(pDoc->createProcessingInstruction(L"xml", L"version=\"1.0\"
> > encoding=\"UTF-8\"", &pProcessInstruction)!=S_OK){
> > strError = "Unable to create xml processing instruction.";
> > throw strError;
> > }
> > if(pDoc->insertBefore(pProcessInstruction, varPointer, &pNode)!=S_OK){
> > strError = "Unable to add xml processing instruction.";
> > throw strError;
> > }
> > if(pNode) pNode->Release();
> > pNode = NULL;
> > pProcessInstruction.Release();
> >
> > How is this supposed to be done?
> >
> > Thanks,
> > David Johns
> >
> >
> 
> I'm not much of a C++ programmer but when I do this I use the first child of
> the Dom, here's an example in script:
> 
> function getDomDoc()
> {
>   var oDom = new ActiveXObject("Msxml2.DomDocument.4.0");
>   oDom.async = false;
>   return oDom
> }
> 
> function main()
> {
>   var oDom = getDomDoc();
>   oDom.loadXML("<root/>");
>   var oPI = oDom.createProcessingInstruction("xml", "version=\"1.0\"
> encoding=\"UTF-8\"");
>   oDom.insertBefore(oPI, oDom.childNodes[0]);
>   WScript.echo(oDom.xml);
> }
> main();
> 
> Hope that gives you some idea.
> 
> As a matter of vocabulary you are not adding a processing instruction but
> the XML declaration (or prologue) although you have to use the
> createProcessingInstruction to do it.
> 
> -- 
> 
> Joe (MVP - XML)
> 
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent