Automatically change the 2nd part of a tag

Questions about XML that are not covered by the other forums should go here.
Gale_D
Posts: 2
Joined: Mon Feb 01, 2010 11:23 pm

Automatically change the 2nd part of a tag

Post by Gale_D »

I am new to XML editing, having trained myself, and I cannot figure out how to do this action:

I was using this tag: <name type="place"></name>, and I want to change it to <placeName></placeName>. I do not want to have to do this manually for 60+ large XML files.

Is there a way to make Oxygen change the 2nd part of a tag when the first part is changed using Find ->Replace?

Sorry if this is a simple question. I wasn't sure what to search for to find an answer.

thanks,
Gale_D
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Automatically change the 2nd part of a tag

Post by adrian »

Hi,

I'm assuming there is some content between the tags:

Code: Select all

<name type="place">
...(content)
</name>
If there isn't you can simply use the Find/Replace in Files and replace one string with the other.

If there is content between the tags and the name elements aren't nested (name inside another name element) you can do this in two steps with Find -> Find/Replace in Files in Oxygen 11.1(which has XPath and XML filters):

Step 1 - Replace element 'name'(with attribute type="place") -> 'placeName':
Text to find: 'name'
Case sensitive, Whole words only
Restrict to XPath: //name[@type="place"]
Enable XML search options(checked)
Search only in: Element names(checked)
Replace with: 'placeName'

Make sure the correct scope and filters are specified.
You can try first a 'Find All' to check if it does what is expected and then 'Replace All'.

Step 2 - Remove ' type="place"' from elements 'placeName':
Text to find: ' type="place"'
Case sensitive
Restrict to XPath: //placeName[@type="place"]
Enable XML search options(unchecked)
Replace with: ''(empty)

Again make sure the correct scope and filters are specified and maybe try a Find All to check the find results.

Let me know if you need further help.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Gale_D
Posts: 2
Joined: Mon Feb 01, 2010 11:23 pm

Re: Automatically change the 2nd part of a tag

Post by Gale_D »

Thank you for the tip...

one problem I have with the "replace element 'name' with 'placeName'" --

'name' closes several other 'xName' tags. So if I replace all of 'name' with 'placeName', I'll end up with (for example) a tag like this:

<personName>content</placeName>
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Automatically change the 2nd part of a tag

Post by adrian »

Gale_D wrote:'name' closes several other 'xName' tags.
You mean you have an XML file that has tags like this <personName>content</name> ? But that's not even XML well-formed, shouldn't you correct those first?

XPath and XML search options do not work on documents that are not XML well-formed so it's going to be very difficult to do what you want.

Please correct me if I misunderstood.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply