I am trying to append an xml tag to my existing xml file using XMLTask (external task) in Ant Script.Following is my code for that
When i try to build the above Ant script, I get the following error taskdef class com.oopsconsultancy.xmltask.ant.XmlTask cannot be found
using the classloader AntClassLoaderI dont understand why i am getting this error,Can anybody help me in resolving this issue? Thank you in advance.
You need to add place the JAR file containing XmlTask into the classpath. Do this by either adding a classpath or classpathref attribute to the <taskdef> (recommended), or by placing the JAR file in the ant_home/lib directory.
Do what the error message says - check the XML you are processing to see if it references any DTDs or XSDs.
By the way, are you dong this from home or from work? If from work, your IT department might be blocking the network request - you might want to ask them about it (though good luck in getting them to change anything!). In that case you might have to remove the DTDs from the XML before processing it and then add it back in afterwards (yes, this is an ugly solution).
Joined: Dec 20, 2012
Thanks for the solution and sorry for the delay in response .As you had guessed i executed the script when i was in my office and yes after removing the DTD i was able to run the script.
I have one issue regarding the xml tag insertion ,Following is the xml in the source file
I am copying the source file contents to a new xml file and i am trying to add a tag after the session factory tag
Following is the ant script for that
Though the build is succesful and the contents of the source file are present in the destination file ,the tag is not getting inserted
Can you please suggest where i had gone wrong? thank you in advance
I suspect that the path value for the <insert> is incorrect, it probably requires an XPath value. I'm not an XPath expert, but I would try path="/hibernate-configuration/session-factory"
Joined: Dec 20, 2012
Hats off you to Peter ..I did as you said and have got the correct output, following are the code changes that i have made
Once i again thanks for your time and patience
Adding to the above points i have a small query ....u had earlier mentioned that i need to manually remove DTD from XML files...is there any task in Ant or XMLTask to comment/remove the DTD of an XML file?
Realize that when an XML file is opened by an XML parser that the DTD is evaluated as part of opening the file. Thus you cannot use any XML-specific task to do this job. However, you could first copy the XML file as text and use a filter to remove the DTD. Check out the lineContainsRegex filterchain: http://ant.apache.org/manual/Types/filterchain.html#linecontainsregexp
Joined: Dec 20, 2012
thanks for the reply , I did as you have advised.
I copied the contents of the xml to a text file and tried using lineContainsRegex filterchain.However i couldnot remove the DTD form the text file, I then tried
using the following task
which commented the DTDs and solved my problem.
Please provide your valuable feedback on this do correct me if have done any mistake.
Thanks a lot for your time and patience
I usually don't like updating files in-place; whenever you do that you have to remember not to commit the file to the source code repository, which can become a nightmare it you accidentally forget and let it happen anyway (I constantly curse one of our third-party apps that insists on doing this very same thing, and thus guarantees that the builds fail 50% of the time). If a <replace> works, you should be able to do a <copy> with a <filterchain). (If you cant't figure that out, at least copy the file first and then do the replace on the copy.)
In general, NEVER change any source files. Instead, always copy to another location to manipulate them. This is one reason why I recommend that everyone learn Maven, if nothing but to emulate how Maven handles files and directories. If you look at the source code for my book, you'll see that I use Ant to do builds but I followed the Maven directory structure and Maven's best practice for never modifying source files.>
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Error while running Ant script for appending an XML tag using XMLTask