Increment Item number within Row

I am updating and XML file and need someway to increment an item number for each row so it is unique. I am used Notepad++ but have tried Excel and notepad can can find no easy way to do this except manually

Here is sample
<Setting name="ExcludedItem_0" value="3|7|C:\*"/>
<Setting name="ExcludedItem_2" value="3|7|C:\*"/>
<Setting name="ExcludedItem_3" value="3|7|C:\*"/>

I need to update the ExcludedItem number and have over 800 lines so i am open to suggestions
LVL 21
compdigit44Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SimonCommented:
= "<Setting name=" & CHAR(34) & "ExcludedItem_" & ROW() & CHAR(34) & " value=" & CHAR(34) & "3|7|C:\*" & CHAR(34) & "/

Try the above. This just uses ROW() to insert the current row number, but you could equally well refer to a list of numeric values in a separate column.

Note that it uses CHAR(34) to insert all the quote marks, so the quote marks you see in the formula are NOT the quote marks in the results.
0
oBdACommented:
XML should be treated as such, so a bit of Powershell should do the trick (source and target files can be the same if you're feeling it's safe to overwrite the original file).
If the only nodes named "Setting" are the ones you want to process, the XPath in the script should work.
If you only want them at a certain level, you need to adjust the $XPath variable accordingly (like "/root/whatever/Setting"; and just in case: keep in mind that XML is case sensitive:
 
$XmlSource = "C:\Temp\test.xml"
$XmlTarget = "C:\Temp\test2.xml"
$XPath = "//Setting"
$NamePrefix = "ExcludedItem_"
[xml]$xml = Get-Content $XmlSource
$Index = 0
ForEach ($Node In $xml.SelectNodes($XPath)) {
	$Node.SetAttribute("name", $NamePrefix + $Index++)
}
$xml.Save($XmlTarget)

Open in new window

0
compdigit44Author Commented:
Thanks for the feed back everyone...

For the powershell script for the $path.. would I just input this: "ExcludedItem_"
0
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

oBdACommented:
No. The script queries for nodes named "Setting" and sets the attribute "name".
Again: if all nodes in the the xml file named "Setting" should be processed like this, the existing XPath "//Setting" will do the trick.
If not, $XPath needs to be set to the path with the "Setting" nodes you want to process.
For the following XML, the XPath would need to be "/root/Whatever/Setting" (remember: XML is cAsE sEnSiTiVe, so "root" is not the same as "Root"):
<root>
	<Whatever>
		<Setting name="ExcludedItem_0" value="3|7|C:\*" />
		<Setting name="ExcludedItem_2" value="3|7|C:\*" />
		<Setting name="ExcludedItem_3" value="3|7|C:\*" />
	</Whatever>
</root>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
compdigit44Author Commented:
Thanks.... I work but edit all sections of my document.. Could the script be used against a text file?
0
oBdACommented:
What do you mean with "Could the script be used against a text file?"? Do you have several of these xml files, or do you mean textual replacement instead of setting XML attributes?
0
compdigit44Author Commented:
Disregard ,my previous post  made a stupid mistake on my end. You script worked perfectly...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.