VC程序中生成了数据库文件;(基于对话框的小程序,)现在想增加打印功能,打算使用
XML格式并显示,
问题是:
1)不知道在VC中如何实现将数据库转换为XML文件。
2)在VC程序中如何调用生成好的XML(XSL)文件。

解决方案 »

  1.   

    1。用sqlserver,直接返回xml结果集
    2。用msxml解析
      

  2.   

    我用的是mdb,而且不使用ACCESS的支持。结果必须要自己转换。各位帮忙。
      

  3.   

    你的意思是象打开普通文件一样打开mdb文件,然后提取数据并xml格式化吗?
      

  4.   

    void CWriteKeyDlg::OnButtonReport() 
    {
    if(!UpdateData())return; CString strSQL,strTimeField,strTableName,strXMLFile,strStylesheet; switch(m_iReportType){
    case 0:
    strTableName="Rockey";
    strTimeField="LastWriteDate";
    break;
    case 1:
    strTableName="RockeyWrite";
    strTimeField="WriteDate";
    break;
    }
    strSQL.Format("Select * From %sReport",strTableName);
    strXMLFile.Format("%s.xml",strTableName);
    strStylesheet.Format("type='text/xsl' href='%s.xsl'",strTableName);
    CString strFilter;
    COleDateTime dtFrom=COleDateTime::GetCurrentTime();
    int nDateDiff=0;
    switch(m_iPeriod){
    case 0:nDateDiff=1;break;
    case 1:nDateDiff=7;break;
    case 2:nDateDiff=15;break;
    case 3:nDateDiff=30;break;
    case 4:nDateDiff=60;break;
    case 5:break;
    }
    dtFrom-=COleDateTimeSpan(nDateDiff,0,0,0);
    if(m_iPeriod!=5){
    strFilter.Format("%s>=#%s#",strTimeField,dtFrom.Format());
    }

    try{
    MSXML2::IXMLDOMDocument2Ptr pDoc("Msxml2.DOMDocument.4.0");
    ado20::_RecordsetPtr pset("ADODB.Recordset");
    MSXML2::IXMLDOMProcessingInstructionPtr pProcessingInstruction;
    MSXML2::IXMLDOMElementPtr pElement;
    MSXML2::IXMLDOMElementPtr pRoot;
    ado20::FieldsPtr pFields;

    pset->Open((LPCTSTR)strSQL,_variant_t((IDispatch *)theApp.m_pConnection,true) ,adOpenDynamic,adLockOptimistic,adCmdUnspecified); pset->Filter=(LPCTSTR)strFilter;
    int nFieldCount=pset->Fields->Count;

    pProcessingInstruction=pDoc->createProcessingInstruction("xml",
    "version='1.0' encoding='gb2312'");
    pDoc->appendChild(pProcessingInstruction);
    pProcessingInstruction=pDoc->createProcessingInstruction("xml-stylesheet",
    (LPCTSTR)strStylesheet);
    pDoc->appendChild(pProcessingInstruction);
    pRoot=pDoc->createElement("Data");
    pDoc->appendChild(pRoot);
    pFields=pset->Fields;
    while(pset->EndOfFile==VARIANT_FALSE){
    pElement=pDoc->createElement("Row");
    for(long i=0;i<nFieldCount;i++){
    if(pFields->Item[i]->Value.vt!=VT_NULL)
    pElement->setAttribute(pFields->Item[i]->Name,pFields->Item[i]->Value);
    }
    pRoot->appendChild(pElement);
    pset->MoveNext();
    }
    pset->Close();
    pDoc->save((LPCTSTR)strXMLFile);
    }
        catch(_com_error &e)
        {
            // Notify the user of errors if any.
            // Pass a connection pointer accessed from the Connection.
            PrintProviderError(theApp.m_pConnection);
            PrintComError(e);
        }
    ShellExecute(NULL, NULL, strXMLFile, NULL, NULL, SW_SHOWNORMAL);
    }
    关于PrintProviderError和PrintComError的实现,参照XML4.0和ADO的SDK文档。
      

  5.   

    不知道在VC6中能否使用DOM。哪位给个例子谈谈。