Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2005, 11:36 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Translating a XML with XSL and saving results

Whats wrong with the following?
The Transform returns an empty xml doc. I have tested the XML and XSL in Internet Explorer and they always return results.

    CoInitialize(NULL);

    MSXML2::IXMLDOMDocumentPtr pXml(MSXML2::CLSID_DOMDocument);
    MSXML2::IXMLDOMDocumentPtr pXslt(CLSID_FreeThreadedDOMDocument);
    MSXML2::IXSLTemplatePtr pTemplate(CLSID_XSLTemplate);
    MSXML2::IXSLProcessorPtr pProcessor;

        pXml.CreateInstance("Msxml2.FreeThreadedDOMDocumen t");
    pXml->async=false;
    pXml->load(_variant_t( m_strSourceFile));

    pXslt.CreateInstance("Msxml2.FreeThreadedDOMDocume nt");
    pXslt->async=false;
    pXslt->load(_variant_t( m_strTemplateFile));

    pTemplate->putref_stylesheet(pXslt);
    pProcessor = pTemplate->createProcessor();

    MSXML2::IXMLDOMDocumentPtr resultxml;
    HRESULT hr = resultxml.CreateInstance("Msxml2.FreeThreadedDOMDo cument");
    resultxml->async=false;

    pProcessor->put_output(_variant_t(resultxml));

    pProcessor->put_input(_variant_t((IUnknown*)pXml));


    pProcessor->transform();

    BSTR theXML;
    resultxml->get_xml(&theXML);
    if(_bstr_t(theXML).length()<1)
        return false;

    resultxml->save(_variant_t( m_strResultsFile));
    return true;


 
Old April 9th, 2005, 07:32 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm afraid my C++ is pretty lame but two things, does your transform produce xml, not html or text? If either of these last two then you'll need a stream to output to rather than a domdocument.

Secondly you should specify the version numbers on the prog ids and make sure they all match, Msxml2.FreeThreadedDOMDocument.4.0 for instance.

Can you post the xml and xslt if this doesn't help?

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
translating XML into CSV file vxc2222 XSLT 1 December 29th, 2007 12:01 PM
Saving results as Excel chrscote Classic ASP Databases 3 August 9th, 2007 05:56 PM
Problem with saving results grid to a file vgeier SQL Server 2000 2 June 1st, 2007 11:42 PM
XML, XSL:FO- saving position() mikevn123 XSLT 0 August 8th, 2006 02:51 PM
translating a flat xml to a hierarchical xml stevea XSLT 4 June 13th, 2005 05:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.