IXMLDOMNode用于字符串? [英] IXMLDOMNode for string?
问题描述
我有一个字符串,其中包含xml节点的xml表示形式,我打算将其插入到内存中加载的xml文档中。 xml字符串(节点)是这样的
I have a string which contains the xml representation of an xml node which I intend to insert in a xml document loaded in memory. The xml string (of node)is something like this
<ns1:Feature name=\"PageSize\">\
<ns1:Option name=\"A4\" />\
</ns1:Feature>
所以,它也有标签名称的命名空间。
有没有办法实现这个目标?
1)我尝试使用XMLDomNode-> put_text(),但它不起作用,因为它取代了<和>通过文本表示形式的字符(< etc。)
2)我想知道是否在单独的内存中xml文档中加载字符串缓冲区然后获取节点从那里的指针将在我的原始文档上工作。但同样,不确定XMLDOMnodes是否可以在文档中转移。
So , it has got namespace for the tag names as well.
Is there a way I can achieve this?
1)I tried to user XMLDomNode->put_text() , but it does not work as it replaces the "<" and ">" chars by their text representations (<etc.)
2) I was wondering if loading the string buffer in a separate in-memory xml document and then getting the node pointer from there will work on my original document. But again , not sure if the XMLDOMnodes are transferable within documents.
推荐答案
要将XMLDOMNode从一个xml导入到另一个xml,你必须使用importNode
来自IXMLDOMDocument3
界面。
你无法从中添加节点没有importNode
的其他文档中的xml文档。
例如:
To import an XMLDOMNode from one xml to an other one, you have to useimportNode
from theIXMLDOMDocument3
interface.
you cannot add a node from an xml document inside an other document withoutimportNode
.
For example:
MSXML2::IXMLDOMDocument3Ptr xml;
xml.CreateInstance(__uuidof(DOMDocument60));
MSXML2::IXMLDOMElementPtr elt = xml->createElement("root");
xml->appendChild(elt);
MSXML2::IXMLDOMDocument3Ptr subxml;
subxml.CreateInstance(__uuidof(DOMDocument60));
subxml->loadXML(fromString);
MSXML2::IXMLDOMNodePtr node = xml->importNode(subxml->GetdocumentElement(),VARIANT_TRUE);
elt->appendChild(node);
我没有检查包含命名空间的subxml节点。
DOMDocument60在导入XML v6时可用
I did not check with subxml nodes that contains namespace.
DOMDocument60 is available when importing XML v6
#import <msxml6.dll>
#include <msxml6.h>
#include <msxml.h>
我自己使用第二种方法解决了这个问题:
1)根据
I solved this myself using the 2nd approach:
1) Create an in-memory xml document based on
IXMLDOMDocument3
接口创建一个内存中的xml文档,并在其中加载xml字符串。
2)使用
interface and load the xml string in there.
2) Select the node you require using the
selectNode()
方法选择所需的节点。
3)现在回到您想要放置节点的orinial xml文档,并将其作为IXMLDOMDocument3接口重新加载。
4 )使用IXMLDOMDo的
method.
3) Now go back to your orinial xml document where you want the node placed and load it again as a IXMLDOMDocument3 interface.
4) Use the
importNode()
方法第3步中的cument3克隆在步骤2中获得的节点。
5)您现在可以使用克隆节点执行
method of IXMLDOMDocument3 from step 3 to clone the node obtained in step 2.
5) You can now use the cloned node to do an
appendChild()
到原始的xml。
这篇关于IXMLDOMNode用于字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!