以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  用VC建好XML了  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=66898)


--  作者:我想学好XML
--  发布时间:9/6/2008 12:49:00 PM

--  用VC建好XML了
代码如下:
MSXML2::IXMLDOMDocumentPtr pDoc;
    MSXML2::IXMLDOMElementPtr  xmlRoot ;
        //创建DOMDocument对象
    HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
    if(!SUCCEEDED(hr))
    {  
        printf("无法创建DOMDocument对象,请检查是否安装了MS XML Parser 运行库!");
        return ;
    }
  //根节点的名称为picturesave
     //创建元素并添加到文档中
     xmlRoot=pDoc->createElement((_bstr_t)"picturesave");

     //设置属性
     pDoc->appendChild(xmlRoot);
     MSXML2::IXMLDOMElementPtr pNode;

     //添加“content”元素
     pNode=pDoc->createElement((_bstr_t)"content");
     xmlRoot->appendChild(pNode);

  //保存到文件
     //如果不存在就建立,存在就覆盖
     pDoc->save("d:\\1.xml");
然后出来的1.XML就一点内容如下:
<picturesave><content/></picturesave>
这个应该是不合法的吧?连版本声明那些的都没有
我怎么才能搞一个合法的?不合法的到时候还能解析么?


--  作者:Qr
--  发布时间:9/6/2008 1:46:00 PM

--  
[C/C++]
C/C++ Syntax
HRESULT createProcessingInstruction(
    BSTR target,
    BSTR data,
    IXMLDOMProcessingInstruction **pi);
Parameters
target [in]
The target part of the processing instruction. It supplies the nodeName property of the new object.
data [in]
The remainder of the processing instruction preceding the closing ?> characters. It supplies the nodeValue property for the new object.
pi [out, retval]
The address of the new IXMLDOMProcessingInstruction object.
C/C++ Return Values
S_OK
The value returned if successful.
E_INVALIDARG
The value returned if the pi parameter is Null.
E_FAIL
The value returned if an error occurs.
--  作者:我想学好XML
--  发布时间:9/6/2008 3:59:00 PM

--  
不明白
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
3,781.250ms