如何使用 vbscript 在现有 xml 中添加属性 [英] how to add a attribute in existing xml using vbscript

查看:15
本文介绍了如何使用 vbscript 在现有 xml 中添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xml,我正在使用 VBSript 生成它.

I have below xml and I am using VBSript to generate it.

<?xml version="1.0"?>
<tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:481-86880-2" Managed="10682">
  <tcm:Item ID="tcm:481-594051"/>
  <tcm:Item ID="tcm:481-594088"/>
  <tcm:Item ID="tcm:481-594089"/>
  <tcm:Item ID="tcm:481-594090"/>
  <tcm:Item ID="tcm:481-594343"/>
  <tcm:Item ID="tcm:481-594344"/>
  <tcm:Item ID="tcm:481-594578"/>
</tcm:ListItems>

现在我有一个pageURL (/english/destinations_offers/destinations/asiapacific/maldives.aspx),这将在匹配ID后显示,例如下面的伪代码

Now I have got a pageURL (/english/destinations_offers/destinations/asiapacific/maldives.aspx), this will be shown after matching the ID for example below pseudocode

从上面的 XML ID 将被匹配,然后我们将 pageURL 属性添加到上面的 xml.所以输出如下:

From above XML ID will be matched and then we will add the pageURL attribute to above xml. So the output will come as below:

<?xml version="1.0"?>
<tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:481-86880-2" Managed="10682">
  <tcm:Item ID="tcm:481-594051"/>
  <tcm:Item ID="tcm:481-594088"/>
  <tcm:Item ID="tcm:481-594089"/>
  <tcm:Item ID="tcm:481-594090"/>
  <tcm:Item ID="tcm:481-594343" pageURL="/english/destinations_offers/destinations/asiapacific/maldives.aspx"/>
  <tcm:Item ID="tcm:481-594344"/>
  <tcm:Item ID="tcm:481-594578"/>
</tcm:ListItems>

请建议使用VBSCript

Please suggest using VBSCript

谢谢.

推荐答案

这是一个使用 MSXML.

Dim doc
Dim pageUrl
Dim itemNode

Set doc = CreateObject("MSXML2.DOMDocument")
doc.load("test.xml")
doc.setProperty "SelectionNamespaces", "xmlns:tcm='http://www.tridion.com/ContentManager/5.0'"

Set itemNode = doc.selectSingleNode("/tcm:ListItems/tcm:Item[@ID = 'tcm:481-594343']")

Set pageUrl = doc.createAttribute("pageURL") 
pageUrl.Value = "/english/destinations_offers/destinations/asiapacific/maldives.aspx" 
itemNode.attributes.setNamedItem(pageUrl) 

应用于您提供的 XML 示例时.它产生以下输出.

When applied to the XML sample you provided. It produces the following output.

<?xml version="1.0"?>
<tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:481-86880-2" Managed="10682">
    <tcm:Item ID="tcm:481-594051"/>
    <tcm:Item ID="tcm:481-594088"/>
    <tcm:Item ID="tcm:481-594089"/>
    <tcm:Item ID="tcm:481-594090"/>
    <tcm:Item ID="tcm:481-594343" pageURL="/english/destinations_offers/destinations/asiapacific/maldives.aspx"/>
    <tcm:Item ID="tcm:481-594344"/>
    <tcm:Item ID="tcm:481-594578"/>
</tcm:ListItems>

这篇关于如何使用 vbscript 在现有 xml 中添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆