Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Inserting an xml value based on the value before

Status
Not open for further replies.

boy3696

Programmer
Dec 7, 2009
1
CA
Hi gang:

Very new to xml here. I'm playing around with it for my own personal website just so I can get exposure.
I have a huge xml file that contains many of the below block of tags:

<image>
<id>14</id>
<title>Title 1</title>
<description>Description 1</description>
<description>Description 2</description>
<description>Description 3</description>
<description>Description 4</description>
<description>Description 5</description>
<description>Description 6</description>
<imageurl>image.jpg</imageurl>
<linkurl></linkurl>
</image>

I have approximately 100 of the above blocks in one xml file of course with different data in each tag (the above is just an example).

Here's my question:
Is there a script of any kind I can run to take the <imageurl> value (image.jpg) and update the <linkurl> tag with the same name except with the .html extension. (ie: image.html)

I'm very new to all this so anything easy to point me to would be most appreciated. I just have no clue what scripting language I can use to do this. I want to get/write a script because I have other large xml files like this that I will need to change at some point.

Thanking everyone in advance.
DB.
 
'even i know this isnt the most efficient way?

Set xmlDom = CreateObject("Msxml.DOMDocument")
xmlDom.Load "path to xml file"
For Each xmlNode In xmlDom.documentElement.childNodes
If xmlNode.nodeName = "image" Then
strTemp = GetText(xmlNode, "imageurl")
Call UpdateText(xmlNode, "linkurl", Replace(strTemp, ".jpg", ".html")
End If
Next
xmlDom.Save "path to xml file"


Function UpdateText(ByRef objNode, ByVal strSingleNode, strPassed)
Dim nodeTemp
Set nodeTemp = objNode.SelectSingleNode(strSingleNode)
nodeTemp.Text = strPassed
End Function


Function GetText(objNode, strSubNode)
On Error Resume Next
Dim objTemp, childNode
WScript.echo "GetText " & strSubNode
GetText = ""
'lord knows why selectsinglenode doesnt work, i give up
'MsgBox objNode.Xml
If strSubNode <> "" Then
If strSubNode = "xml" Then
GetText = objNode.Xml
Else
Set objTemp = objNode.SelectSingleNode(strSubNode)
Err.Clear
GetText = objTemp.Text
If Err.Number <> 0 Then
GetText = "_nf_"
End If
Set objTemp = Nothing
End If
Else
GetText = objNode.Text
End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top