web前端

位置:IT落伍者 >> web前端 >> 浏览文章

创建、查询、修改带名称空间的XML文件


发布日期:2018年08月22日
 
创建、查询、修改带名称空间的XML文件
XML的应用越来越广泛了如VistaFlex编程都将使用 XML正确掌握XML的各种操作对提高编程效率至关重要下面就是一个综合处理带名称空间的XML的例子

C#

string wNameSpace = ;

SystemXmlXmlDocument doc = new SystemXmlXmlDocument();

//创建根节点

SystemXmlXmlNode root = docCreateNode(SystemXmlXmlNodeTypeElement w wordDocument );

SystemXmlXmlAttribute xa;

xa = docCreateAttribute(xmlns v wNameSpace);

xaValue = urn:schemasmicrosoftcom:vml;

rootAttributesAppend(xa);

//为节点添加属性

xa = docCreateAttribute(xmlns w wNameSpace);

xaValue = urn:schemasmicrosoftcom:office:word;

rootAttributesAppend(xa);

xa = docCreateAttribute(xmlns SL wNameSpace);

xaValue = ;

rootAttributesAppend(xa);

xa = docCreateAttribute(xmlns aml wNameSpace);

xaValue = ;

rootAttributesAppend(xa);

xa = docCreateAttribute(xmlns wx wNameSpace);

xaValue = ;

rootAttributesAppend(xa);

xa = docCreateAttribute(xmlns o wNameSpace);

xaValue = urn:schemasmicrosoftcom:office:office;

rootAttributesAppend(xa);

xa = docCreateAttribute(xmlns dt wNameSpace);

xaValue = uuid:CFBdAFAAC;

rootAttributesAppend(xa);

xa = docCreateAttribute(xmlns space wNameSpace);

xaValue = preserve;

rootAttributesAppend(xa);

//为节点增加值

SystemXmlXmlNode body = docCreateNode(SystemXmlXmlNodeTypeElement v body urn:schemasmicrosoftcom:vml);

SystemXmlXmlNode childNode = docCreateNode(SystemXmlXmlNodeTypeElement o t urn:schemasmicrosoftcom:office:office);

childNodeInnerText = 欢迎光临【孟宪会之精彩世界】;

//添加到内存树中

bodyAppendChild(childNode);

rootAppendChild(body);

docAppendChild(root);

//添加节点声明

SystemXmlXmlDeclaration xd = docCreateXmlDeclaration( UTF yes);

docInsertBefore(xd docDocumentElement);

//添加处理指令

SystemXmlXmlProcessingInstruction spi = docCreateProcessingInstruction(msoapplication progid=\WordDocument\);

docInsertBefore(spi docDocumentElement);

//查询节点

SystemXmlXmlNamespaceManager nsmanager = new SystemXmlXmlNamespaceManager(docNameTable);

nsmanagerAddNamespace(w );

nsmanagerAddNamespace(v urn:schemasmicrosoftcom:vml);

nsmanagerAddNamespace(o urn:schemasmicrosoftcom:office:office);

SystemXmlXmlNode node = docSelectSingleNode(w:wordDocument/v:body/o:t nsmanager);

ResponseWrite(nodeInnerText);

nodeInnerText = 欢迎光临【孟宪会之精彩世界】:/;

//创建CDATA节点

SystemXmlXmlCDataSection xcds = docCreateCDataSection(<a >【孟宪会之精彩世界】</a>);

nodeParentNodeInsertAfter(xcds node);

ResponseWrite(xcdsInnerText);

docSave(ServerMapPath(testxml));

上一篇:网站间共享数据的WebService

下一篇:WebForm页面内容输出的细节分析