Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How do I change XML files programmatically?
How do I change XML files programmatically? [message #901083] Thu, 09 August 2012 12:21 Go to next message
Nan Li is currently offline Nan Li
Messages: 4
Registered: July 2011
Junior Member
To finish the task I am working on, I need to programmatically change the version, namespace, and schemalocation of a XML file. Does anyone know how to do that? What APIs can I use? Would very appreciate if any response!!

More specific, the file needs to be changed looks like this:

<entity-mappings version="2.0" xmlns="AAA" xmlns:xsi="..." xsi:schemaLocation="AAA .../xml/ns/persistence/orm_2_0.xsd">
</entity-mappings>

I need to programmatically change the file to a XML file as this:

<entity-mappings version="2.4" xmlns="BBB" xmlns:xsi="..." xsi:schemaLocation="BBB http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd">
</entity-mappings>

You can see I need to change the value of the following elements:

- version
- xmlns
- xsi:schemaLocation
Re: How do I change XML files programmatically? [message #901089 is a reply to message #901083] Thu, 09 August 2012 13:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25945
Registered: July 2009
Senior Member
Nan,

Sounds like something that would be pretty easy to do with a DOM.

On 09/08/2012 6:21 PM, Nan Li wrote:
> To finish the task I am working on, I need to programmatically change
> the version, namespace, and schemalocation of a XML file. Does anyone
> know how to do that? What APIs can I use? Would very appreciate if any
> response!!
>
> More specific, the file needs to be changed looks like this:
>
> <entity-mappings version="2.0" xmlns="AAA" xmlns:xsi="..."
> xsi:schemaLocation="AAA .../xml/ns/persistence/orm_2_0.xsd">
> </entity-mappings>
>
> I need to programmatically change the file to a XML file as this:
>
> <entity-mappings version="2.4" xmlns="BBB" xmlns:xsi="..."
> xsi:schemaLocation="BBB
> http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd">
> </entity-mappings>
>
> You can see I need to change the value of the following elements:
>
> - version
> - xmlns
> - xsi:schemaLocation
>
Re: How do I change XML files programmatically? [message #901090 is a reply to message #901089] Thu, 09 August 2012 13:34 Go to previous messageGo to next message
Nan Li is currently offline Nan Li
Messages: 4
Registered: July 2011
Junior Member
Thank you Ed! Could you give me some examples? I am not so familiar with Eclipse + XML.
Re: How do I change XML files programmatically? [message #901145 is a reply to message #901090] Fri, 10 August 2012 01:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25945
Registered: July 2009
Senior Member
I don't think you need any Eclipse-specific tools for the simple things
you've described. Just DOM which comes with the JDK.

On 09/08/2012 7:34 PM, Nan Li wrote:
> Thank you Ed! Could you give me some examples? I am not so familiar
> with Eclipse + XML.
Re: How do I change XML files programmatically? [message #901258 is a reply to message #901083] Fri, 10 August 2012 10:02 Go to previous messageGo to next message
Javin Paul is currently offline Javin Paul
Messages: 45
Registered: July 2011
Location: mumbai
Member

You can also try xml beans for more sophisticated handling. xml beans is like JAXB and binds xml documents to Java object which makes manipulation easy.

i.e. setNamespace() will set the name space.


Re: How do I change XML files programmatically? [message #901335 is a reply to message #901258] Fri, 10 August 2012 16:54 Go to previous message
Nan Li is currently offline Nan Li
Messages: 4
Registered: July 2011
Junior Member
Problem solved. It is indeed pretty simple. Thanks for your response!!
Previous Topic:eclipse workspace
Next Topic:Troubleshooting Eclipse 4.2 Performance - How?
Goto Forum:
  


Current Time: Wed Jul 30 11:18:57 EDT 2014

Powered by FUDForum. Page generated in 0.03141 seconds