Parsing xml tagdata and settagdata

I am wondering the best approach to parsing and then updating data in an xml file. This file will have multiple instances of the same tags, a simple example is below. I know tagdata(TEXT, HEADER, TRAILER, ITEM) can grab the data from the nth item but how would I then update the nth item in the xml file? It would be great to have this settagdata PAGE, PREFIX, SUFFIX, DATA, SEP include an ITEM parameter. I am trying to think how I could use arraychange( but im not sure what seperator will work. the xml uses lf()

 <Phone>
    <Kind>Work</Kind>
    <Number></Number>
    <Ext></Ext>
</Phone>

<Phone>
    <Kind>Work</Kind>
    <Number></Number>
    <Ext></Ext>
</Phone>

Here is a method to replace the data of any specific tag if there are multiple tags of the same name. The gettaglocations statement creates an array of the matching tag locations with their starting position and their total length. We extract info for the particular tag item we want and use setxtagvalue to change that data and then reassemble the text back together again inserting our change in its proper place in the original text. You could also have a check to make sure the item number is not larger than the number of matching tags in the text. This example uses an extended version of your sample text and changes whatever tag data is set by the xmlitem variable.

let xmlText="<Phone>
    <Kind>Work</Kind>
    <Number></Number>
    <Ext></Ext>
</Phone>

<Phone>
    <Kind>Home</Kind>
    <Number>12345</Number>
    <Ext></Ext>
</Phone>

<Phone>
    <Kind>Home</Kind>
    <Number></Number>
    <Ext></Ext>
</Phone>"
let xmlStart=0 let xmlEnd=0 let xmlitem=3
gettaglocations xmlText, "<Number", ">", xmlStart
xmlEnd=val(array(arraycolumn(xmlStart, 2, cr(), ";"),xmlitem,cr()))
xmlStart=val(array(arraycolumn(xmlStart, 1, cr(), ";"),xmlitem,cr()))
xmlEnd=xmlStart+xmlEnd
let tempXML=xmlText[xmlStart,xmlEnd]
setxtagvalue tempXML,"Number","45879",ΒΆ
xmlText=xmlText[1,xmlStart-1]+tempXML+xmlText[xmlEnd+1,-1]
message xmlText

You could roll this into a custom statement like the one you suggested using parameters for header, trailer, item# and replacement data. Have fun