[Xmltask-users] Issues working with web.xml
Brought to you by:
bagnew
From: Inger, M. <Inger@Synygy.com> - 2005-01-12 19:58:55
|
> I have the following (somewhat shortened) web.xml, which illustrates my > problem > (FYI: I'm using JDK 1.4.2_06, and ANT 1.6.2) > > <?xml version="1.0" encoding="UTF-8"?> > <web-app version="2.4" > xmlns="http://java.sun.com/xml/ns/j2ee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> > > <display-name>Build Web Interface</display-name> > > <context-param> > <param-name>build-scripts-location</param-name> > <param-value>E:\BuildHome</param-value> > </context-param> > > </web-app> > > I am trying to edit the "build-scripts-location" context parameter, but to > illustrate my problem, > i'm just working with the //context-param xpath. I use XMLTask to try to > remove all the context-param > elements as follows: > > <xmltask source="web.xml" dest="web2.xml"> > <remove path="//context-param" /> > <!-- > <replace > path="//context-param/param-name[contains(param-name/text(),'build-scripts > -location')]/param-value/text()" > withText="installLocation"/> > --> > </xmltask> > > However, the output file "web2.xml" contains the following (notice that > the context-param element is still there): > > <?xml version="1.0" encoding="UTF-8"?> > <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee > http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> > > <display-name>Build Web Interface</display-name> > > <context-param> > <param-name>build-scripts-location</param-name> > <param-value>E:\BuildHome</param-value> > </context-param> > > </web-app> > > The following java code runs and indicates that there is 1 element which > matches the xpath expression "//context-param": > > public void test1() > throws Exception > { > DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); > DocumentBuilder db = dbf.newDocumentBuilder(); > Document d = db.parse("web.xml"); > > String xpath= "//context-param"; > NodeIterator it = XPathAPI.selectNodeIterator(d, xpath); > Node node = null; > int cnt = 0; > while ((node = it.nextNode()) != null) { > System.out.println(node.getNodeName()); > cnt++; > } > > assertEquals(1, cnt); > } > > This makes me wonder if XMLTask is using the XPath API that's included in > JDK1.4 or some > other XPath API. > > Finally, i've noticed that if i remove all the attributes, other than > "version" on the web-app element, > that xmltask works ask expected producting the following output: > > <?xml version="1.0" encoding="UTF-8"?> > <web-app version="2.4"> > > <display-name>Build Web Interface</display-name> > > </web-app> > > Can anyone help me in figuring out what's going here? > |