Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: How Do You Create a DOCTYPE Declaration Using MSXML? [Thread Next] Re: How Do You Create a DOCTYPE Declaration Using MSXML?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)
>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
