Thanks for the reply Brian. I've attached sample xml file as well as a bunch of scripts that illustrate the problem. "b" versions differ in that they use nested <actions> instead of separate target.

The main difference between your xml file and mine is that in mine namespace is set using xmls attribute instead of xmlns:prefix attribute.

Michal

Brian Agnew wrote:
Michael,

Thx for the below. Can you provide a simplified input XML document for the
below so we both know what we're looking at wrt. inputs ?

Note the following appears better:
<target name="abc">
        <xmltask source="a.xml" dest="b.xml">
                <call path="/yh:some/yh:path" target="process-node">
                        <param name="value" path="yh:subpath/text()"/>
                </call>
        </xmltask>
</target>
<target name="process-node">
        <echo>Process node called with ${value}</echo>
</target>

where the input document is:

<yh:some xmlns:yh="http://www.yahoo.com"; xmlns="http://junk.com";>
        <yh:path>
                <yh:subpath>1</yh:subpath>
        </yh:path>
        <yh:path>
                <yh:subpath>2</yh:subpath>
        </yh:path>
</yh:some>

Second question: when you look to modify the XML within the target of a
<call>, how are you passing it ? As a buffer and into XMLTask again ? Or
as a property ?

Brian

On Wed, May 28, 2008 17:33, Micha^(3) Tkacz wrote:
Hello Brian,

I have following namespace-related problem, which I'm unable to solve.
Maybe you can help me, otherwise it's something to consider for the next
version of xmltask.

I have an xml document where each node comes from the same namespace.
I'm trying to loop over all nodes matching an xpath using <call>. For
each node I need to access certain subnodes.


Script 1:

<call path="/:some/:path" target="process-node">
    <param name="value" path=":sub-node/text()"/>
</call>

throws

javax.xml.transform.TransformerException: A location path was expected,
but the following token was encountered:  :sub-node


Script 2:

<call path="/:some/:path" target="process-node">
    <param name="value" path="/:sub-node/text()"/>
</call>

(slash added) fails to match sub-node element.


Script 3:

<call path="/:some/:path" target="process-node" buffer="node"/>

[...]

<target name="process-node">
    <xmltask sourcebuffer="node">
       <copy path=":sub-node/text()" property="value"/>
    </xmltask>
</target>

throws

javax.xml.transform.TransformerException: A location path was expected,
but the following token was encountered:  :sub-node


Script 4:

<call path="/:some/:path" target="process-node" buffer="node"/>

[...]

<target name="process-node">
    <xmltask sourcebuffer="node">
       <copy path="*/*:sub-node/text()" property="value"/>
    </xmltask>
</target>

(slash added) throws

com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception:
Prefix must resolve to a namespace:


Using nested actions instead of target doesn't change anything. Using
"sub-node/text()" without a colon fails to match sub-node element for
obvious reasons.


Is there a way to achieve what I need with xmltask 1.15.1?

Another idea: <call> seems to make a copy of a matching node which makes
it impossible to modify it so that the changes are reflected in original
document. How about adding additional parameter, saying whether a copy
should be made or not?

Help will be much appreciated.

Michal

Brian Agnew wrote:
Hi -

A number of issues have come up recently regarding XMLTask and
namespaces.
I think these can be reduced to 2 fundamental issues:

1) XPaths for namespace-enabled documents are confusing. Or rather,
people
are not aware of how these should work.

2) Inserting non-namespaced documents/fragments into namespace-enabled
documents doesn't quite work as expected (resulting in empty xmlns
attributes and the like)

(I believe that XMLTask is doing what it's asked to correctly - however
XMLTask exists to make people's lives easier and so we should be asking
it
to do more)

I aim to fix both the above in the next release (no ETA, since I have no
spec!). If there are other namespace issues that you believe are not
covered in the above and that are causing you grief, please let me know.
The development of XMLTask is driven solely by customer requests now!

Brian


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/_______________________________________________
Xmltask-users mailing list
Xmltask-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xmltask-users




<root xmlns="http://example.com";>
	<entry>
		<key>message</key>
		<value>hello xmltask</value>
	</entry>
	<entry>
		<key>foo</key>
		<value>bar</value>
	</entry>
</root>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry" target="process-node">
			    <param name="key" path=":key/text()"/>
			    <param name="value" path=":value/text()"/>
			</call>
		</xmltask>
	</target>
	
	<target name="process-node">
		<echo>${key} = ${value}</echo>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry">
			    <param name="key" path=":key/text()"/>
			    <param name="value" path=":value/text()"/>
				<actions>
					<echo>@{key} = @{value}</echo>
				</actions>
			</call>
		</xmltask>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry" target="process-node">
			    <param name="key" path="/:key/text()"/>
			    <param name="value" path="/:value/text()"/>
			</call>
		</xmltask>
	</target>
	
	<target name="process-node">
		<echo>${key} = ${value}</echo>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry">
			    <param name="key" path="/:key/text()"/>
			    <param name="value" path="/:value/text()"/>
				<actions>
					<echo>@{key} = @{value}</echo>
				</actions>
			</call>
		</xmltask>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry" target="process-node" buffer="node"/>
		</xmltask>
	</target>
	
	<target name="process-node">
		<xmltask sourcebuffer="node">
			<copy path=":key/text()" property="key"/>
			<copy path=":value/text()" property="value"/>
		</xmltask>
		<echo>${key} = ${value}</echo>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry" buffer="node">
				<actions>
					<xmltask sourcebuffer="node">
						<copy path=":key/text()" property="key"/>
						<copy path=":value/text()" property="value"/>
					</xmltask>
					<echo>${key} = ${value}</echo>
				</actions>
			</call>
		</xmltask>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry" target="process-node" buffer="node"/>
		</xmltask>
	</target>
	
	<target name="process-node">
		<xmltask sourcebuffer="node">
			<copy path="/:key/text()" property="key"/>
			<copy path="/:value/text()" property="value"/>
		</xmltask>
		<echo>${key} = ${value}</echo>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<call path="/:root/:entry" buffer="node">
				<actions>
					<xmltask sourcebuffer="node">
						<copy path="/:key/text()" property="key"/>
						<copy path="/:value/text()" property="value"/>
					</xmltask>
					<echo>${key} = ${value}</echo>
				</actions>
			</call>
		</xmltask>
	</target>
	
</project>
<project default="default">

	<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpath="xmltask-v1.15.1.jar"/>
	
	<target name="default">
		<xmltask source="sample.xml">
			<copy path="/:root/:entry/:key/text()" property="key"/>
			<copy path="/:root/:entry/:value/text()" property="value"/>
		</xmltask>
		<echo>${key} = ${value}</echo>
	</target>
	
</project>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Xmltask-users mailing list
Xmltask-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xmltask-users

Reply via email to