RE: [nant-dev] New XML tasks and functions

2006-02-14 Thread Joao.hugo.miranda



Sure, as soon as I have some time, probably this week. 
:)


From: John Ludlow 
[mailto:[EMAIL PROTECTED] Sent: segunda-feira, 13 de 
Fevereiro de 2006 19:46To: João Hugo Miranda (DNC)Cc: 
nant-developers@lists.sourceforge.netSubject: Re: [nant-dev] New XML 
tasks and functions
Ok, I've made a few improvements to my copy. Joao, would you 
mind trying this version and letting me know how you get on, please? 
Thanks in advance. ;)Some things to note with it, though: 
This is an updated NAnt.Core.dll , so delete the XmlExtensions one if that's 
what you're using. Also if you're using that version, the XmlPoke2 task is 
now part of XmlPoke. From that it gets the benefit of namespaces and all 
kinds of funkiness like that, and also will (hopefully) be merged into the trunk 
copy of NAnt. Summary of the changes, then. 

  There's now an XmlTaskContainer for the for-each task, which in turn 
  inherits from TaskContainer. Other than that, it's just the same as 
  XmlTask. (Again, because of this, this task should be able to understand 
  namespaces). 
  All-round better error handling. xml::get-value() and 
  xml::get-value-without-failing() don't return an error if the XPath points to 
  a node, rather than a value. I think get-value should, but I'm still 
  thinking about how it could make that decision. If you want to ensure it 
  fails under this situation, and the value you want isn't an attribute, you can 
  put '/text()' in the xpath, like so: 
  
echo message="${xml::get-value(/root/test/text())}"/
  Better error messages.There are still some issues. The 
way the functions seem to be reading the XML data is causing some strange 
formatting issues, which could be annoying if you want to read data in then 
write it out again, then edit or read the resulting file manually. And the 
functions don't support namespaces. I'm considering making changes to the 
_expression_ evaluator so that it can support a namespace manager, and I was 
looking into the code for the evaluator today. 
RegardsJohn
On 13/02/06, John 
Ludlow [EMAIL PROTECTED] 
wrote:
Hi 
  Joao,Thanks for your feedback, 
  and I'm glad you found it useful. I'll look into the issues with the 
  error messages (I think that in the code it should have general catch handlers 
  that throw a BuildException, since anything else results in a not-very-clear 
  messag). Were the messages you got saying INTERNAL ERROR?John
  
  On 13/02/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  
Hi,

Just to 
give you notice of my experience with you xml tasks and 
functions.

Overall, 
all went smoothly and most important, it solved my needs perfectly. There 
were only minor quirks with error conditions, or should I say error messages 
as they were not very clear. For example:

  
  If the 
  Xml-ForEach task doesn't find the source Xml it blows without giving a 
  very informative message.
  
  If the XPath 
  query given to get-value-without-failing (and I assume the get-value) 
  function resturns a node and not a value, the function again fails without 
  a clear message.
Thanks 
again for your effort! It was (is) most useful.

João


From: John Ludlow [mailto:[EMAIL PROTECTED]] Sent: sábado, 28 de 
Janeiro de 2006 16:43To: João Hugo Miranda 
(DNC)Subject: Re: [nant-dev] New XML tasks and 
    functions

On 28/01/06, [EMAIL PROTECTED] [EMAIL PROTECTED]  wrote: 

  Well, 
  what can I say but thank you? I never cease to be amazed byhow some 
  people can be so incredibly helpful. I'll give it a try as soon as I can 
  and keep you posted.
Well, that's the nature of a community project like this. My 
life has been made so much easier by, shall we say "the kindness of 
strangers", and it's nice to give something back. It also means that 
future updates might be easier for me if this becomes widely adopted and 
integrated into the NAnt release at some point. 

  Thanks 
  again!
  João 
  (Curious... João means John in portuguese :) ) 

Aha! I wondered if it meant something like that. I know 
Juan is Spanish for John. Nice to meet a fellow John out there! 
;) 

  
  
  From: John Ludlow [mailto:[EMAIL PROTECTED]] Sent: 
  sábado, 28 de Janeiro de 2006 16:19To: João Hugo Miranda 
  (DNC)Subject: Fwd: [nant-dev] New XML tasks and 
  functions
  
  Hi, Just remembered I'd sent it to someone else, so 
  I'll just forward you the same email (probably easier than you waiting for 
  me to get into work on Monday).Attached to this email should be a 
  zip with the source code and binaries in. Copy the assembly into the 
  NAnt\bin folder. Alternatively, I have also attached a build file 
  which you can include into your build (though I've noticed that 
  the xml-foreach task in that on

Re: [nant-dev] New XML tasks and functions

2006-02-13 Thread John Ludlow
Ok, I've made a few improvements to my copy. Joao, would you mind trying this version and letting me know how you get on, please? Thanks in advance. ;)Some things to note with it, though: This is an updated NAnt.Core.dll
, so delete the XmlExtensions one if that's what you're using. Also if you're using that version, the XmlPoke2 task is now part of XmlPoke. From that it gets the benefit of namespaces and all kinds of funkiness like that, and also will (hopefully) be merged into the trunk copy of NAnt.
Summary of the changes, then. There's now an XmlTaskContainer for the for-each task, which in turn inherits from TaskContainer. Other than that, it's just the same as XmlTask. (Again, because of this, this task should be able to understand namespaces). 
All-round better error handling. xml::get-value() and xml::get-value-without-failing() don't return an error if the XPath points to a node, rather than a value. I think get-value should, but I'm still thinking about how it could make that decision. If you want to ensure it fails under this situation, and the value you want isn't an attribute, you can put '/text()' in the xpath, like so:
echo message=${xml::get-value(/root/test/text())}/Better error messages.There are still some issues. The way the functions seem to be reading the XML data is causing some strange formatting issues, which could be annoying if you want to read data in then write it out again, then edit or read the resulting file manually. And the functions don't support namespaces. I'm considering making changes to the _expression_ evaluator so that it can support a namespace manager, and I was looking into the code for the evaluator today.
RegardsJohnOn 13/02/06, John Ludlow [EMAIL PROTECTED] wrote:
Hi Joao,Thanks for your feedback, and I'm glad you found it useful. I'll look into the issues with the error messages (I think that in the code it should have general catch handlers that throw a BuildException, since anything else results in a not-very-clear messag).
Were the messages you got saying INTERNAL ERROR?JohnOn 13/02/06, 
[EMAIL PROTECTED]
 [EMAIL PROTECTED] wrote:






Hi,

Just to give you notice of my experience with you xml tasks 
and functions.

Overall, all went smoothly and most important, it solved my 
needs perfectly. There were only minor quirks with error conditions, or should I 
say error messages as they were not very clear. For example:

  
  If the Xml-ForEach task doesn't find the source Xml it blows without 
  giving a very informative message.
  
  If the XPath query given to get-value-without-failing (and I assume the 
  get-value) function resturns a node and not a value, the function again fails 
  without a clear message.
Thanks again for your effort! It was (is) most 
useful.

João


From: John Ludlow 
[mailto:[EMAIL PROTECTED]] Sent: sábado, 28 de Janeiro de 2006 
16:43To: João Hugo Miranda (DNC)Subject: Re: [nant-dev] 
New XML tasks and functions

On 28/01/06, [EMAIL PROTECTED]

 
[EMAIL PROTECTED] 
 wrote:

  Well, what 
  can I say but thank you? I never cease to be amazed byhow some people 
  can be so incredibly helpful. I'll give it a try as soon as I can and keep you 
  posted.
Well, that's the nature of a community project like this. My life 
has been made so much easier by, shall we say the kindness of strangers, and 
it's nice to give something back. It also means that future updates might 
be easier for me if this becomes widely adopted and integrated into the NAnt 
release at some point. 

  Thanks 
  again!
  João 
  (Curious... João means John in portuguese :) ) 
Aha! I wondered if it meant something like that. I know 
Juan is Spanish for John. Nice to meet a fellow John out there! ;) 


  
  
  From: John Ludlow [mailto:[EMAIL PROTECTED]] 

Sent: sábado, 28 
  de Janeiro de 2006 16:19To: João Hugo Miranda 
  (DNC)Subject: Fwd: [nant-dev] New XML tasks and 
  functions
  
  Hi, Just remembered I'd sent it to someone else, so I'll 
  just forward you the same email (probably easier than you waiting for me to 
  get into work on Monday).Attached to this email should be a zip with 
  the source code and binaries in. Copy the assembly into the NAnt\bin 
  folder. Alternatively, I have also attached a build file which you can 
  include into your build (though I've noticed that the 
  xml-foreach task in that one is a little behind the assembly version, 
  in that it doesn't support the index attribute). I've submitted a patch 
  to Ian MacLean that provides these functions and an updated xmlpoke 
  task, so you might see these features in a future version of NAnt. One 
  thing I think the other guy found confusing (so I might change it) is that by 
  default the get elements don't return an error if they couldn't find 
  the node. I figured you could do a property::exists() call. It's a 
  trivial change, though, and in the meantime you can always set the failonerror 
  attribute for get to true. Anyway, let me know how it 
  goes. Glad I could help

Re: [nant-dev] New XML tasks and functions

2006-02-07 Thread John Ludlow
The updated task (using the code from Dries) is at home :( I'll email it tonight (I meant to copy it to my MP3 player or my GMail drive, but forgot. Sorry)Wouldn't the NamespaceManager on Project be a different instance to the one on the Task, therefore have a different set of namespaces?
JohnOn 07/02/06, Martin Aliger [EMAIL PROTECTED] wrote:





Namespacemanager on Element should be there for namespace 
handling of nant build file itself. I do not test this funcionality, but we're 
solving this issue some time ago.

I'm 
looking forward to get a look into your changed tasks. Is it on nightlies 
already or have you a patch somewhere?

Thanks,
Martin


  
  
  From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]] On Behalf Of John 
  LudlowSent: Tuesday, February 07, 2006 12:21 AMTo: Dries 
  Verbeke; nant-developers@lists.sourceforge.netSubject: Re: 
  [nant-dev] New XML tasks and functions
  Ok, I've integrated your changes into my copy, Dries. I can 
  forward you the binaries if you want to test it, but I'm not sure what kind of 
  a difference this will make. As far as I know, the updated XmlPoke I did 
  should support namespaces. Probably the XmlPoke2 task doesn't, but that 
  was probably why Ian asked if I could merge my task with the existing one. 
  There is the Xml-Foreach task which this might come in handy for, but 
  I haven't submitted that. The functions still don't support namespaces 
  because they're not element-aware, and I think the original question was could 
  they support namespaces. I think it might be an idea if the functions 
  could find out where they were called from, and get the namespacemanager that 
  way. (BTW, there is a namespacemanager in the Element class, so 
  it's possible that we could just get that rather than needing a base class for 
  XmlTask. Having said that, there's a case for having an XmlTask base 
  anyway as there's some common functionality there.) I get the feeling 
  I'm missing something fairly obvious. Anyway, I'm off to bed since I'm 
  tired and I have an interview tomorrow. :) See ya 
  later.John
  On 06/02/06, John 
  Ludlow [EMAIL PROTECTED] 
  wrote:
  I'm 
pretty new to it myself ;) I'll take a look at the changes and see if 
I can get it built and tested, and I'll let you know what 
happens.CheersJohn

On 06/02/06, Dries 
Verbeke [EMAIL PROTECTED] wrote:
Hi 
  John,i re-read the original thread and concluded that what they wanted 
  was just the same behaviour as the xmlpeek and xmlpoke task so I 
  refactored the functionality out of those task and put it in an abstract 
  base class 'XmlTask'. Nowyour new tasks can easily inherit from this 
  task and have the same functionality (read multiple namespaces). 
  In the attachments a cvs patch file. Keep in mind that I'm 
  new to this opensource thing and didn't add a lot of comments to the 
  changes. I also placed the abstract class in the same namespace as 
  the other default task. So check it out and let me know what 
  you think of it
  DriesJohn Ludlow  
  [EMAIL PROTECTED] wrote:
  Hi,Unless 
I'm missing something, it's a slightly larger job than that. I've 
added a property into my copy of the NAnt source, but I can't see how to 
make the _expression_ evaluator care about that property. It doesn't 
reference Task at all, so I don't think it could (in its current 
implementation) know that a namespace has been specified on the task and 
it should apply that namespace. I'll see if I can get it to work 
out the task instance that has been run and from there whether or not to 
apply a namespace. If anyone has any ideas, please email 
me.CheersJohn
On 03/02/06, John 
Ludlow [EMAIL PROTECTED] wrote: 
Ok, 
  wasn't sure if that's what you meant. I'm working on something 
  else at the moment but I'll take a look when I get the chance. 
  
  On 03/02/06, Dries Verbeke  
  [EMAIL PROTECTED] wrote:
  That 
's correct it needs to be added to the Abstract Task class so we can 
add it as a default property and (but this needs to be checked out) 
I think it doesn't matter where you put the namespace references the 
NamespaceManager will contain all namespace declarations of an xml 
document it's associated to. In the microsoft doc's there is 
something mentioned as scope management. It could be that only 
the task tag or any parent tags are useable ...At the 
moment I don't have a compilable version of the Nant source as soon 
as can I'll check this or if you have some time ... the only 
thing we need to agree is the name of the Property ... it may not 
conflict with existing properties in any subclass ...so let 
me know what

Re: [nant-dev] New XML tasks and functions

2006-02-07 Thread John Ludlow
That was meant to say This zip file has the updated source and NAnt.Core.dll :/JohnOn 07/02/06, John Ludlow 
[EMAIL PROTECTED] wrote:This zip file has the 
On 07/02/06, John Ludlow 
[EMAIL PROTECTED] wrote:
The updated task (using the code from Dries) is at home :( I'll email it tonight (I meant to copy it to my MP3 player or my GMail drive, but forgot. Sorry)Wouldn't the NamespaceManager on Project be a different instance to the one on the Task, therefore have a different set of namespaces?
JohnOn 07/02/06, Martin Aliger 


[EMAIL PROTECTED] wrote:





Namespacemanager on Element should be there for namespace 
handling of nant build file itself. I do not test this funcionality, but we're 
solving this issue some time ago.

I'm 
looking forward to get a look into your changed tasks. Is it on nightlies 
already or have you a patch somewhere?

Thanks,
Martin


  
  
  From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]] On Behalf Of John 
  LudlowSent: Tuesday, February 07, 2006 12:21 AMTo: Dries 
  Verbeke; nant-developers@lists.sourceforge.netSubject: Re: 
  [nant-dev] New XML tasks and functions
  Ok, I've integrated your changes into my copy, Dries. I can 
  forward you the binaries if you want to test it, but I'm not sure what kind of 
  a difference this will make. As far as I know, the updated XmlPoke I did 
  should support namespaces. Probably the XmlPoke2 task doesn't, but that 
  was probably why Ian asked if I could merge my task with the existing one. 
  There is the Xml-Foreach task which this might come in handy for, but 
  I haven't submitted that. The functions still don't support namespaces 
  because they're not element-aware, and I think the original question was could 
  they support namespaces. I think it might be an idea if the functions 
  could find out where they were called from, and get the namespacemanager that 
  way. (BTW, there is a namespacemanager in the Element class, so 
  it's possible that we could just get that rather than needing a base class for 
  XmlTask. Having said that, there's a case for having an XmlTask base 
  anyway as there's some common functionality there.) I get the feeling 
  I'm missing something fairly obvious. Anyway, I'm off to bed since I'm 
  tired and I have an interview tomorrow. :) See ya 
  later.John
  On 06/02/06, John 
  Ludlow [EMAIL PROTECTED] 
  wrote:
  I'm 
pretty new to it myself ;) I'll take a look at the changes and see if 
I can get it built and tested, and I'll let you know what 
happens.CheersJohn

On 06/02/06, Dries 
Verbeke [EMAIL PROTECTED] wrote:
Hi 
  John,i re-read the original thread and concluded that what they wanted 
  was just the same behaviour as the xmlpeek and xmlpoke task so I 
  refactored the functionality out of those task and put it in an abstract 
  base class 'XmlTask'. Nowyour new tasks can easily inherit from this 
  task and have the same functionality (read multiple namespaces). 
  In the attachments a cvs patch file. Keep in mind that I'm 
  new to this opensource thing and didn't add a lot of comments to the 
  changes. I also placed the abstract class in the same namespace as 
  the other default task. So check it out and let me know what 
  you think of it
  DriesJohn Ludlow  
  [EMAIL PROTECTED] wrote:
  Hi,Unless 
I'm missing something, it's a slightly larger job than that. I've 
added a property into my copy of the NAnt source, but I can't see how to 
make the _expression_ evaluator care about that property. It doesn't 
reference Task at all, so I don't think it could (in its current 
implementation) know that a namespace has been specified on the task and 
it should apply that namespace. I'll see if I can get it to work 
out the task instance that has been run and from there whether or not to 
apply a namespace. If anyone has any ideas, please email 
me.CheersJohn
On 03/02/06, John 
Ludlow [EMAIL PROTECTED] wrote: 
Ok, 
  wasn't sure if that's what you meant. I'm working on something 
  else at the moment but I'll take a look when I get the chance. 
  
  On 03/02/06, Dries Verbeke  
  [EMAIL PROTECTED] wrote:
  That 
's correct it needs to be added to the Abstract Task class so we can 
add it as a default property and (but this needs to be checked out) 
I think it doesn't matter where you put the namespace references the 
NamespaceManager will contain all namespace declarations of an xml 
document it's associated to. In the microsoft doc's there is 
something mentioned as scope management. It could be that only 
the task tag or any parent tags are useable ...At the 
moment I don't have a compilable version of the Nant source as soon 
as can I'll check

Re: [nant-dev] New XML tasks and functions

2006-02-06 Thread John Ludlow
I'm pretty new to it myself ;) I'll take a look at the changes and see if I can get it built and tested, and I'll let you know what happens.CheersJohnOn 06/02/06, 
Dries Verbeke [EMAIL PROTECTED] wrote:
Hi John, i re-read the original thread and concluded that what they  wanted was just the same behaviour as the xmlpeek and xmlpoke task so I  refactored the functionality out of those task and put it in an  abstract base class 'XmlTask'. Nowyour new tasks can easily  inherit from this task and have the same functionality (read multiple  namespaces). 
   In the attachments a cvs patch file.  Keep in mind that I'm new to this opensource thing and didn't add a lot  of comments to the changes. I also placed the abstract class in  the same namespace as the other default task. 
So check it out and let me know what you think of itDriesJohn Ludlow 
[EMAIL PROTECTED] wrote:  Hi,Unless  I'm missing something, it's a slightly larger job than that. I've  added a property into my
 copy of the NAnt source, but I can't see how  to make the _expression_ evaluator care about that property. It  doesn't reference Task at all, so I don't think it could (in its  current implementation) know that a namespace has been specified on the  task and it should apply that namespace. 
I'll see if I can get  it to work out the task instance that has been run and from there  whether or not to apply a namespace. If anyone has any ideas,  please email me.CheersJohn
  On 03/02/06, John Ludlow [EMAIL PROTECTED] wrote:
  Ok, wasn't sure if that's what you meant. I'm working on  something else at the moment but I'll take a look when I get the chance.
On 03/02/06,   Dries Verbeke   
[EMAIL PROTECTED] wrote:  That 's correct it needs to be added to the Abstract Task class so we  can add it as a default property and (but this needs to be checked out)  I think it doesn't matter where you put the namespace references the  NamespaceManager will contain all namespace declarations of an xml  document it's associated to. 
   In the microsoft doc's there  is something mentioned as scope management. It could be that only  the task tag or any parent tags are useable ...   At the  moment I don't have a compilable version of the Nant source as soon as  can I'll
 check this or if you have some time ...the only  thing we need to agree is the name of the Property ... it may not  conflict with existing properties in any subclass ...so let me know what you can find out
  Dries  John Ludlow [EMAIL PROTECTED] wrote:
Hmmm... It would have to be implemented on more than just the  echo task - I just included that as an example, but I think that  useage wouldn't be as useful as, say, the property  task. You could do something like that for the property  task, I guess, but there's other situations where properties are  useful. If you wanted to take the values of an XML document and  post them to a database, for
 example, ou could use the XML functions  within the nantcontrib sql tasks. Similarly, to append to  a document or merge the contents of a document into another, you can  (with my patch to the xmlpoke task, or with my xmlpoke2 task) do  something like this: 
xmlpoke file=xmlfile.xml xpath//data   ![CDATA[   ${xml::get-xml(other.xml, '//data[test = 'true']')}   myothertag value=123/
   ]]/xmlpoke  I'm not sure where you'd put the xmlns:x definition in this case.  I suppose you could put them as attributes of the xmlpoke task:xmlpoke file=
xmlfile.xml xpath//x2:data xmlns:x=   
 http://www.gordic.cz/shared/project-config/v_1.0.0.0 xmlns:x2=  
  http://www.gordic.cz/shared/project-config/v_2.0.0.0 ![CDATA[   ${xml::get-xml(other.xml, '//x:data[test = 'true']')} myothertag value=123/ ]]
/xmlpokeWould this work? If so, I'd suggest these modifications to the base   Task class, so that this can be used in any task.John  On 03/02/06, 
Dries Verbeke [EMAIL PROTECTED] wrote:
  Hi,  maybe a stuppid idee but why cant we have some kind of mechanisme to  add the NamespaceManager of our nant build xml file to the task so you  can add multiple Namespace in an xml fashioned way ... echo message=${xml::get-value-using-ns('
test.xml',  '/x:configuration/x:appSettings/x:[EMAIL PROTECTED] = ''server'']/@value')}   xmlns:x=  
http://www.gordic.cz/shared/project-config/v_1.0.0.0  xmlns:x2=  
http://www.gordic.cz/shared/project-config/v_2.0.0.0/To do this we only need to add an extra property to the abstract Task  class and fill it with the
 NamespaceManager available at that moment  ... and from their on every task can use this extra property. just brain storming ...  Dries  
Get the latest photos from your camera to your friends  family fast and easy with   
PhotoMail  from Yahoo! Mail.
		 
Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews,  more on new and used cars.



Re: [nant-dev] New XML tasks and functions

2006-02-06 Thread John Ludlow
Ok, I've integrated your changes into my copy, Dries. I can forward you the binaries if you want to test it, but I'm not sure what kind of a difference this will make. As far as I know, the updated XmlPoke I did should support namespaces. Probably the XmlPoke2 task doesn't, but that was probably why Ian asked if I could merge my task with the existing one.
There is the Xml-Foreach task which this might come in handy for, but I haven't submitted that. The functions still don't support namespaces because they're not element-aware, and I think the original question was could they support namespaces. I think it might be an idea if the functions could find out where they were called from, and get the namespacemanager that way. 
(BTW, there is a namespacemanager in the Element class, so it's possible that we could just get that rather than needing a base class for XmlTask. Having said that, there's a case for having an XmlTask base anyway as there's some common functionality there.)
I get the feeling I'm missing something fairly obvious. Anyway, I'm off to bed since I'm tired and I have an interview tomorrow. :) See ya later.JohnOn 06/02/06, 
John Ludlow [EMAIL PROTECTED] wrote:
I'm pretty new to it myself ;) I'll take a look at the changes and see if I can get it built and tested, and I'll let you know what happens.CheersJohn
On 06/02/06, 
Dries Verbeke [EMAIL PROTECTED] wrote:

Hi John, i re-read the original thread and concluded that what they  wanted was just the same behaviour as the xmlpeek and xmlpoke task so I  refactored the functionality out of those task and put it in an  abstract base class 'XmlTask'. Nowyour new tasks can easily  inherit from this task and have the same functionality (read multiple  namespaces). 
   In the attachments a cvs patch file.  Keep in mind that I'm new to this opensource thing and didn't add a lot  of comments to the changes. I also placed the abstract class in  the same namespace as the other default task. 
So check it out and let me know what you think of itDriesJohn Ludlow 

[EMAIL PROTECTED] wrote:  Hi,Unless  I'm missing something, it's a slightly larger job than that. I've  added a property into my
 copy of the NAnt source, but I can't see how  to make the _expression_ evaluator care about that property. It  doesn't reference Task at all, so I don't think it could (in its  current implementation) know that a namespace has been specified on the  task and it should apply that namespace. 
I'll see if I can get  it to work out the task instance that has been run and from there  whether or not to apply a namespace. If anyone has any ideas,  please email me.CheersJohn

  On 03/02/06, John Ludlow [EMAIL PROTECTED] wrote:

  Ok, wasn't sure if that's what you meant. I'm working on  something else at the moment but I'll take a look when I get the chance.
On 03/02/06,   Dries Verbeke   

[EMAIL PROTECTED] wrote:  That 's correct it needs to be added to the Abstract Task class so we  can add it as a default property and (but this needs to be checked out)  I think it doesn't matter where you put the namespace references the  NamespaceManager will contain all namespace declarations of an xml  document it's associated to. 
   In the microsoft doc's there  is something mentioned as scope management. It could be that only  the task tag or any parent tags are useable ...   At the  moment I don't have a compilable version of the Nant source as soon as  can I'll
 check this or if you have some time ...the only  thing we need to agree is the name of the Property ... it may not  conflict with existing properties in any subclass ...so let me know what you can find out
  Dries  John Ludlow [EMAIL PROTECTED] wrote:

Hmmm... It would have to be implemented on more than just the  echo task - I just included that as an example, but I think that  useage wouldn't be as useful as, say, the property  task. You could do something like that for the property  task, I guess, but there's other situations where properties are  useful. If you wanted to take the values of an XML document and  post them to a database, for
 example, ou could use the XML functions  within the nantcontrib sql tasks. Similarly, to append to  a document or merge the contents of a document into another, you can  (with my patch to the xmlpoke task, or with my xmlpoke2 task) do  something like this: 
xmlpoke file=xmlfile.xml xpath//data   ![CDATA[   ${xml::get-xml(other.xml, '//data[test = 'true']')}   myothertag value=123/

   ]]/xmlpoke  I'm not sure where you'd put the xmlns:x definition in this case.  I suppose you could put them as attributes of the xmlpoke task:xmlpoke file=
xmlfile.xml xpath//x2:data xmlns:x=   
 http://www.gordic.cz/shared/project-config/v_1.0.0.0 xmlns:x2=  

  http://www.gordic.cz/shared/project-config/v_2.0.0.0 ![CDATA[   ${xml::get-xml(other.xml, '//x:data[test = 'true']')} myothertag value=123/ ]]
/xmlpokeWould this work? If so, I'd suggest 

RE: [nant-dev] New XML tasks and functions

2006-02-06 Thread Martin Aliger



Namespacemanager on Element should be there for namespace 
handling of nant build file itself. I do not test this funcionality, but we're 
solving this issue some time ago.

I'm 
looking forward to get a look into your changed tasks. Is it on nightlies 
already or have you a patch somewhere?

Thanks,
Martin


  
  
  From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED] On Behalf Of John 
  LudlowSent: Tuesday, February 07, 2006 12:21 AMTo: Dries 
  Verbeke; nant-developers@lists.sourceforge.netSubject: Re: 
  [nant-dev] New XML tasks and functions
  Ok, I've integrated your changes into my copy, Dries. I can 
  forward you the binaries if you want to test it, but I'm not sure what kind of 
  a difference this will make. As far as I know, the updated XmlPoke I did 
  should support namespaces. Probably the XmlPoke2 task doesn't, but that 
  was probably why Ian asked if I could merge my task with the existing one. 
  There is the Xml-Foreach task which this might come in handy for, but 
  I haven't submitted that. The functions still don't support namespaces 
  because they're not element-aware, and I think the original question was could 
  they support namespaces. I think it might be an idea if the functions 
  could find out where they were called from, and get the namespacemanager that 
  way. (BTW, there is a namespacemanager in the Element class, so 
  it's possible that we could just get that rather than needing a base class for 
  XmlTask. Having said that, there's a case for having an XmlTask base 
  anyway as there's some common functionality there.) I get the feeling 
  I'm missing something fairly obvious. Anyway, I'm off to bed since I'm 
  tired and I have an interview tomorrow. :) See ya 
  later.John
  On 06/02/06, John 
  Ludlow [EMAIL PROTECTED] 
  wrote:
  I'm 
pretty new to it myself ;) I'll take a look at the changes and see if 
I can get it built and tested, and I'll let you know what 
happens.CheersJohn

On 06/02/06, Dries 
Verbeke [EMAIL PROTECTED] wrote:
Hi 
  John,i re-read the original thread and concluded that what they wanted 
  was just the same behaviour as the xmlpeek and xmlpoke task so I 
  refactored the functionality out of those task and put it in an abstract 
  base class 'XmlTask'. Nowyour new tasks can easily inherit from this 
  task and have the same functionality (read multiple namespaces). 
  In the attachments a cvs patch file. Keep in mind that I'm 
  new to this opensource thing and didn't add a lot of comments to the 
  changes. I also placed the abstract class in the same namespace as 
  the other default task. So check it out and let me know what 
  you think of it
  DriesJohn Ludlow  
  [EMAIL PROTECTED] wrote:
  Hi,Unless 
I'm missing something, it's a slightly larger job than that. I've 
added a property into my copy of the NAnt source, but I can't see how to 
make the _expression_ evaluator care about that property. It doesn't 
reference Task at all, so I don't think it could (in its current 
implementation) know that a namespace has been specified on the task and 
it should apply that namespace. I'll see if I can get it to work 
out the task instance that has been run and from there whether or not to 
apply a namespace. If anyone has any ideas, please email 
me.CheersJohn
On 03/02/06, John 
Ludlow [EMAIL PROTECTED] wrote: 
Ok, 
  wasn't sure if that's what you meant. I'm working on something 
  else at the moment but I'll take a look when I get the chance. 
  
  On 03/02/06, Dries Verbeke  
  [EMAIL PROTECTED] wrote:
  That 
's correct it needs to be added to the Abstract Task class so we can 
add it as a default property and (but this needs to be checked out) 
I think it doesn't matter where you put the namespace references the 
NamespaceManager will contain all namespace declarations of an xml 
document it's associated to. In the microsoft doc's there is 
something mentioned as scope management. It could be that only 
the task tag or any parent tags are useable ...At the 
moment I don't have a compilable version of the Nant source as soon 
as can I'll check this or if you have some time ... the only 
thing we need to agree is the name of the Property ... it may not 
conflict with existing properties in any subclass ...so let 
me know what you can find out DriesJohn 
Ludlow [EMAIL PROTECTED] wrote:

Hmmm... 
  It would have to be implemented on more than just the echo task - 
  I just included that as an example, but I think that useage 
  wouldn't be as useful as, say, the property task. 
  You could

Re: [nant-dev] New XML tasks and functions

2006-02-03 Thread John Ludlow
Hi,Unless I'm missing something, it's a slightly larger job than that. I've added a property into my copy of the NAnt source, but I can't see how to make the _expression_ evaluator care about that property. It doesn't reference Task at all, so I don't think it could (in its current implementation) know that a namespace has been specified on the task and it should apply that namespace.
I'll see if I can get it to work out the task instance that has been run and from there whether or not to apply a namespace. If anyone has any ideas, please email me.CheersJohn
On 03/02/06, John Ludlow [EMAIL PROTECTED] wrote:
Ok, wasn't sure if that's what you meant. I'm working on something else at the moment but I'll take a look when I get the chance.On 03/02/06, 
Dries Verbeke
 [EMAIL PROTECTED] wrote:

That 's correct it needs to be added to the Abstract Task class so we  can add it as a default property and (but this needs to be checked out)  I think it doesn't matter where you put the namespace references the  NamespaceManager will contain all namespace declarations of an xml  document it's associated to.
In the microsoft doc's there is something mentioned as scope  management. It could be that only the task tag or any  parent tags are useable ...At the moment I don't have a compilable version of the Nant source as soon as can I'll check this or if you have some time ...
the only thing we need to agree is the name of the Property ... it may not conflict with existing properties in any subclass ...so let me know what you can find out  Dries
John Ludlow [EMAIL PROTECTED] wrote:
  Hmmm... It would have to be implemented on more than just the echo  task - I just included that as an example, but I think that useage  wouldn't be as useful as, say, the property task. You could do  something like that for the property task, I guess, but there's  other situations where properties are useful. If you wanted to take  the values of an XML document and post them to a database, for example,  ou could use the XML functions within the nantcontrib sql  tasks. Similarly, to append to a document or merge the contents of a  document into another, you can (with my patch to the xmlpoke task, or  with my xmlpoke2 task) do something like this:
xmlpoke file=xmlfile.xml xpath//data   ![CDATA[   ${xml::get-xml(other.xml, '//data[test = 'true']')}   myothertag value=123/

   ]] 
 /xmlpoke  I'm not sure where you'd put the xmlns:x definition in this case. I  suppose you could put them as attributes of the xmlpoke task:xmlpoke file=xmlfile.xml xpath//x2:data xmlns:x=
  http://www.gordic.cz/shared/project-config/v_1.0.0.0 xmlns:x2=
  http://www.gordic.cz/shared/project-config/v_2.0.0.0 ![CDATA[
 ${xml::get-xml(other.xml, '//x:data[test = 'true']')} myothertag value=123/ ]]/xmlpokeWould this work? If so, I'd suggest these modifications to the base
 Task class, so that this can be used in any task.John  On 03/02/06, Dries Verbeke 

[EMAIL PROTECTED] wrote:  Hi,  maybe a stuppid idee but why cant we have some kind of mechanisme to  add the NamespaceManager of our nant build xml file to the task so you  can add multiple Namespace in an xml fashioned way ...
echo message=${xml::get-value-using-ns('test.xml',  '/x:configuration/x:appSettings/x:[EMAIL PROTECTED] = ''server'']/@value')}   xmlns:x=  

http://www.gordic.cz/shared/project-config/v_1.0.0.0  xmlns:x2=  

http://www.gordic.cz/shared/project-config/v_2.0.0.0/  To do this we only need to add an extra property to the abstract Task  class and fill it with the NamespaceManager available at that moment  ... and from their on every task can use this extra property.
just brain storming ...  Dries  
		Get the latest photos from your camera to your friends  family fast and easy with 
PhotoMail  from Yahoo! Mail.





Re: [nant-dev] New XML tasks and functions

2006-02-01 Thread John Ludlow
Sorry for the message spam, but I have one final update.I couldn't figure out how to allow multiple namespaces, since NAnt seem to doesn't have any concept of a params array parameter for functions. I thought about this and I'm not entirely sure why you'd want to specify multiple namespaces anyway (I was just trying to replicate the existing xmlpeek task), so I gave up and just allowed you to specify one namespace.
If you wanted to replicate the example given in the xmlpeek help, this is how you'd do it:echo message=${xml::get-value-using-ns('test.xml', '/x:configuration/x:appSettings/x:[EMAIL PROTECTED] = ''server'']/@value', xml::get-ns('x', '
http://www.gordic.cz/shared/project-config/v_1.0.0.0'))}/xml::get-ns(string prefix, string uri)Will create you a namespace object from the prefix and uri that you pass in
xml::get-value-using-ns(string xmlFile, string xPath, XmlNamespace xmlNamespace)Will get a value using the namespace you pass in.This is the code for it:  public static string GetXmlValueUsingNamespaces(string xmlFile, string xPath, XmlNamespace xmlNamespace)
 { XmlDocument xd = new XmlDocument(); xd.Load(xmlFile); XmlNamespaceManager nsMgr = new XmlNamespaceManager(xd.NameTable); XmlNamespace xns = new XmlNamespace();
 if (xmlNamespace.IfDefined  !xmlNamespace.UnlessDefined)  { nsMgr.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri); } try
 { string s = xd.SelectSingleNode(xPath, nsMgr).Value; } catch(NullReferenceException err) { throw new BuildException(The specified node could not be found, err);
 } return s; } [Function(get-ns)] public static XmlNamespace GetNamespace(string prefix, string uri) { XmlNamespace xn = new XmlNamespace();
 xn.Prefix = prefix; xn.Uri = uri; return xn; }Let me know if this does the job. If so, I'll adapt the other functions to use namespaces to have similar alternatives when I have more time.
CheersJohnOn 30/01/06, John Ludlow [EMAIL PROTECTED] wrote:
Actually, scratch that. It seems that it needs to implement IConvertible if it needs to pass to that function. I'll carry on looking at it, and let you know how I get on.
On 30/01/06, 
John Ludlow [EMAIL PROTECTED] wrote:

Hi, Martin,I've knocked together the following two functions. I haven't tested them yet, but they don't exactly work ideally anyway. I want to be able to have a params array of XmlNamespace[] as the last parameter, but it won't let me do that because, apparently, XmlNamespace needs to implement IConvertible. I've taken a quick gander at this and it looks like implementing this might be a big job.
If I can get that working, the syntax would be something like  ${xml::get-value-using-ns('test.xml', '/data/something', xml::get-ns('x', '

http://x-uri'), xml::get-ns('y', '
http://y-uri'))}OTOH, there might be a good reason that XmlNamespace doesn't support this interface.What do you think? [Function(get-value-using-ns)] public static string GetXmlValue(string xmlFile, string xPath, XmlNamespace xmlNamespace)
 { XmlDocument xd = new XmlDocument(); xd.Load(xmlFile); XmlNamespaceManager nsMgr = new XmlNamespaceManager(xd.NameTable); XmlNamespace xns = new XmlNamespace();
 if (xmlNamespace.IfDefined  !xmlNamespace.UnlessDefined)  { nsMgr.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri); } string s = 
xd.SelectSingleNode(xPath, nsMgr).Value; return s; } [Function(get-ns)] public static XmlNamespace GetNamespace(string prefix, string uri) {


 XmlNamespace xn = new XmlNamespace(); xn.Prefix = prefix; xn.Uri = uri; return xn; }BTW, I couldn't get your example of a namespace working. It kept complaining about the version number in the preprocessor. I copied the one from the NAnt help which worked ok.
On 30/01/06, Martin Aliger 

[EMAIL PROTECTED] wrote:
Hello,I like it very much. Expecially functions. Bad luck I personally neednamespace support, since mine xmls have some namespace in it. And evendefault namespace needs specification in xpaths :-(

Maybe there could be some elegant way how to pass namespace mapping into
functions. New type come to my mind. It could be elegant perhaps.btw: does nant functions support overloading and/or default parameter value?bool xml::value-exists (string xmlFile, string xPath,
NamespaceMap nsMap = null)===Here is typical use of namespace map (taken from my real script):xmlpeekfile=${prjconfig}
xpath=x:Project/x:ExeNameproperty=newexefailonerror=true
failonnonode=falsenamespacesnamespace
prefix=x uri=http://www.gordic.cz/shared/project-config/v_1.0.0.0
//namespaces
/xmlpeekAnd sample xml file is here (changed to protect innocent):?xml version=1.0 encoding=utf-8?Project xmlns=


http://www.gordic.cz/shared/project-config/v_1.0.0.0Namefoo/NameDescriptionfoobar/DescriptionExeNamefootest/ExeName/Project


===I missed xml-foreach once too, but nowadays I do not need it. Still it couldbe worth addition to NAnt(Contrib) tasks!Martin Aliger -Original Message- From: 


[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
] On Behalf Of John Ludlow Sent: Tuesday, January 24, 2006 7:19 

Re: [nant-dev] New XML tasks and functions

2006-01-30 Thread John Ludlow
Hi, MartinOn 30/01/06, Martin Aliger [EMAIL PROTECTED] wrote:
Hello,I like it very much. Expecially functions. Bad luck I personally neednamespace support, since mine xmls have some namespace in it. And evendefault namespace needs specification in xpaths :-(
I don't know that much about namespaces. Perhaps we could find a way to pass an XMLNamespaceCollection. I'd have to figure out how namespaces change what the function needs to do. I'd also have to figure out a way to do that without causing non-namespaced people to have to think about namespaces. Probably a separate function, since NAnt functions can't be overloaded as far as I can see. xml::get-value-using-ns(string xmlFile, string xPath, string ns) or something, maybe?
btw: does nant functions support overloading and/or default parameter value?
bool xml::value-exists (string xmlFile, string xPath,NamespaceMap nsMap = null)No, I wish it did. (That way, the get-value-without-failing function could be overloaded as get-value (string, string, bool), with the bool indicating whether or not to fail on an error) .
===Here is typical use of namespace map (taken from my real script):
xmlpeekfile=${prjconfig}xpath=x:Project/x:ExeNameproperty=newexe
failonerror=truefailonnonode=falsenamespaces
namespaceprefix=x uri=http://www.gordic.cz/shared/project-config/v_1.0.0.0
//namespaces/xmlpeekAnd sample xml file is here (changed to protect innocent):?xml version=
1.0 encoding=utf-8?Project xmlns=http://www.gordic.cz/shared/project-config/v_1.0.0.0Namefoo/Name
Descriptionfoobar/DescriptionExeNamefootest/ExeName/ProjectCool, that'll help. I'll take a look at the xmlpeek source to see if I can work out how it handles namespaces differently and shamelessly plagiarise - ahem, I mean adapt ;) - that into the function.
===I missed xml-foreach once too, but nowadays I do not need it. Still it could
be worth addition to NAnt(Contrib) tasks!I got  round it with a c# script task. I'd like to revamp that into an xml-foreach call (since I think embedded c# scripts should be avoided if possible). That's why I started this whole thing, in a way. But I agree - I think it could be a worthy addition as well :)
 


Re: [nant-dev] New XML tasks and functions

2006-01-30 Thread Gert Driesen
Martin,

Overloading of functions is not (yet) supported. I'm definitely in favor of
this, but if I recall correctly Ian and Jarek ruled against this in favor of
implicit conversion of function arguments. Ian, please correct me if I'm
wrong.

Gert
- Original Message - 
From: Martin Aliger [EMAIL PROTECTED]
To: 'John Ludlow' [EMAIL PROTECTED];
nant-developers@lists.sourceforge.net
Sent: Monday, January 30, 2006 10:02 AM
Subject: RE: [nant-dev] New XML tasks and functions


Hello,

I like it very much. Expecially functions. Bad luck I personally need
namespace support, since mine xmls have some namespace in it. And even
default namespace needs specification in xpaths :-(

Maybe there could be some elegant way how to pass namespace mapping into
functions. New type come to my mind. It could be elegant perhaps.

btw: does nant functions support overloading and/or default parameter value?
bool xml::value-exists (string xmlFile, string xPath,
NamespaceMap nsMap = null)


===

Here is typical use of namespace map (taken from my real script):

   xmlpeek
file=${prjconfig}
xpath=x:Project/x:ExeName
property=newexe
failonerror=true
failonnonode=false

namespaces

namespace
prefix=x uri=http://www.gordic.cz/shared/project-config/v_1.0.0.0/
/namespaces

/xmlpeek


And sample xml file is here (changed to protect innocent):

?xml version=1.0 encoding=utf-8?
Project xmlns=http://www.gordic.cz/shared/project-config/v_1.0.0.0;
  Namefoo/Name
  Descriptionfoobar/Description
  ExeNamefootest/ExeName
/Project

===

I missed xml-foreach once too, but nowadays I do not need it. Still it could
be worth addition to NAnt(Contrib) tasks!

Martin Aliger


 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On
 Behalf Of John Ludlow
 Sent: Tuesday, January 24, 2006 7:19 PM
 To: nant-developers@lists.sourceforge.net;
 nantcontrib-developer@lists.sourceforge.net
 Subject: [nant-dev] New XML tasks and functions

 Hi, there

 Recently I mentioned on the NAnt Dev list that I have been
 working on XML-handling functionality.  I've got further than
 I had last time, so I thought about summarising what I've
 done here (I'm also happy to share the code and/or binaries,
 so if you want either of these to check it out for yourself,
 just email me at [EMAIL PROTECTED]).  I've put my code
 into an assembly, tested it, and am currently contemplating
 writing some unit tests for it.
 Before I go through that, though, I wanted to get some
 feedback and a better idea of what people thought of this.

 This is what I have so far:

 Functions
 ===

 bool xml::value-exists (string xmlFile, string xPath)
 --
 ---
 Tests whether a specified xpath query returns a value.  If
 this gets a NullReferenceException (usually means an XML
 value doesn't exist).

 string xml::get-value (string xmlFile, string xPath)
 --
 -
 Gets a value returned by an XPath query.  Throws an error if
 the node specified in the xpath is not found.  Duplicates
 some of xmlpeek's functionality, but enables you to use
 ${x} syntax to get an xml value.
  This fits in with the idea that being able to use this
 functionality is nicer if all you want is information.
 However, it does not support namespaces like xmlpeek does.

 string xml::get-value-without-failing (string xmlFile, string xPath)
 --
 -
 Gets a value returned by an XPath query.  As above, but does
 not an error if the node specified in the XPath is not found,
 instead returning a blank string.

 string xml::get-xml (string xmlFile, string xPath) Gets the
 InnerXml property of an XML node returned by an XPath query.

 int xml::count (string xmlFile, string xPath) Gets the number
 of nodes in a document that match the specified XPath query.

 Tasks

 xml-foreach
 =
 Iterates through an XML document.  I thought about making
 this part of the ForEach task, but there seemed to be a
 significant difference in functionality, especially
 concerning getting  the details of each item in the
 iteration.  For this reason, I decided to make a separate task.
  The syntax is explained below:

 Attributes:
 
  - file:  string.  XML file to iterate
  - xpath:  string.  XPath.  The task will essentially iterate
 through the list of nodes that match this query.
  - index:  string.  Optional.  A property that can contain
 the index of a returned result in the node list.  You can use
 this to find this node in the doument again, especially
 useful for nested loops.  By default doesn't set any property.

 Nested elements:
 =
  - do:  The tasks to run on each iteration

  - xmlpropertybinding:  Runs XPath queries on the result,
 putting the returned value in a property.

  - xmlpropertybinding/get

 Attributes

Re: [nant-dev] New XML tasks and functions

2006-01-30 Thread John Ludlow
Hi, Martin,I've knocked together the following two functions. I haven't tested them yet, but they don't exactly work ideally anyway. I want to be able to have a params array of XmlNamespace[] as the last parameter, but it won't let me do that because, apparently, XmlNamespace needs to implement IConvertible. I've taken a quick gander at this and it looks like implementing this might be a big job.
If I can get that working, the syntax would be something like  ${xml::get-value-using-ns('test.xml', '/data/something', xml::get-ns('x', 'http://x-uri'), xml::get-ns('y', '
http://y-uri'))}OTOH, there might be a good reason that XmlNamespace doesn't support this interface.What do you think? [Function(get-value-using-ns)] public static string GetXmlValue(string xmlFile, string xPath, XmlNamespace xmlNamespace)
 { XmlDocument xd = new XmlDocument(); xd.Load(xmlFile); XmlNamespaceManager nsMgr = new XmlNamespaceManager(xd.NameTable); XmlNamespace xns = new XmlNamespace();
 if (xmlNamespace.IfDefined  !xmlNamespace.UnlessDefined)  { nsMgr.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri); } string s = 
xd.SelectSingleNode(xPath, nsMgr).Value; return s; } [Function(get-ns)] public static XmlNamespace GetNamespace(string prefix, string uri) {
 XmlNamespace xn = new XmlNamespace(); xn.Prefix = prefix; xn.Uri = uri; return xn; }BTW, I couldn't get your example of a namespace working. It kept complaining about the version number in the preprocessor. I copied the one from the NAnt help which worked ok.
On 30/01/06, Martin Aliger [EMAIL PROTECTED] wrote:
Hello,I like it very much. Expecially functions. Bad luck I personally neednamespace support, since mine xmls have some namespace in it. And evendefault namespace needs specification in xpaths :-(Maybe there could be some elegant way how to pass namespace mapping into
functions. New type come to my mind. It could be elegant perhaps.btw: does nant functions support overloading and/or default parameter value?bool xml::value-exists (string xmlFile, string xPath,
NamespaceMap nsMap = null)===Here is typical use of namespace map (taken from my real script):xmlpeekfile=${prjconfig}
xpath=x:Project/x:ExeNameproperty=newexefailonerror=true
failonnonode=falsenamespacesnamespace
prefix=x uri=http://www.gordic.cz/shared/project-config/v_1.0.0.0//namespaces
/xmlpeekAnd sample xml file is here (changed to protect innocent):?xml version=1.0 encoding=utf-8?Project xmlns=
http://www.gordic.cz/shared/project-config/v_1.0.0.0Namefoo/NameDescriptionfoobar/DescriptionExeNamefootest/ExeName/Project
===I missed xml-foreach once too, but nowadays I do not need it. Still it couldbe worth addition to NAnt(Contrib) tasks!Martin Aliger -Original Message- From: 
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of John Ludlow Sent: Tuesday, January 24, 2006 7:19 PM
 To: nant-developers@lists.sourceforge.net; nantcontrib-developer@lists.sourceforge.net
 Subject: [nant-dev] New XML tasks and functions Hi, there Recently I mentioned on the NAnt Dev list that I have been working on XML-handling functionality.I've got further than
 I had last time, so I thought about summarising what I've done here (I'm also happy to share the code and/or binaries, so if you want either of these to check it out for yourself, just email me at 
[EMAIL PROTECTED]).I've put my code into an assembly, tested it, and am currently contemplating writing some unit tests for it. Before I go through that, though, I wanted to get some
 feedback and a better idea of what people thought of this. This is what I have so far: Functions === bool xml::value-exists (string xmlFile, string xPath)
 -- --- Tests whether a specified xpath query returns a value.If this gets a NullReferenceException (usually means an XML
 value doesn't exist). string xml::get-value (string xmlFile, string xPath) -- - Gets a value returned by an XPath query.Throws an error if
 the node specified in the xpath is not found.Duplicates some of xmlpeek's functionality, but enables you to use ${x} syntax to get an xml value.This fits in with the idea that being able to use this
 functionality is nicer if all you want is information. However, it does not support namespaces like xmlpeek does. string xml::get-value-without-failing (string xmlFile, string xPath) --
 - Gets a value returned by an XPath query.As above, but does not an error if the node specified in the XPath is not found, instead returning a blank string.
 string xml::get-xml (string xmlFile, string xPath) Gets the InnerXml property of an XML node returned by an XPath query. int xml::count (string xmlFile, string xPath) Gets the number
 of nodes in a document that match the specified XPath query. Tasks xml-foreach = Iterates through an XML document.I thought about 

Re: [nant-dev] New XML tasks and functions

2006-01-30 Thread John Ludlow
Actually, scratch that. It seems that it needs to implement IConvertible if it needs to pass to that function. I'll carry on looking at it, and let you know how I get on.On 30/01/06, 
John Ludlow [EMAIL PROTECTED] wrote:
Hi, Martin,I've knocked together the following two functions. I haven't tested them yet, but they don't exactly work ideally anyway. I want to be able to have a params array of XmlNamespace[] as the last parameter, but it won't let me do that because, apparently, XmlNamespace needs to implement IConvertible. I've taken a quick gander at this and it looks like implementing this might be a big job.
If I can get that working, the syntax would be something like  ${xml::get-value-using-ns('test.xml', '/data/something', xml::get-ns('x', '
http://x-uri'), xml::get-ns('y', '
http://y-uri'))}OTOH, there might be a good reason that XmlNamespace doesn't support this interface.What do you think? [Function(get-value-using-ns)] public static string GetXmlValue(string xmlFile, string xPath, XmlNamespace xmlNamespace)
 { XmlDocument xd = new XmlDocument(); xd.Load(xmlFile); XmlNamespaceManager nsMgr = new XmlNamespaceManager(xd.NameTable); XmlNamespace xns = new XmlNamespace();
 if (xmlNamespace.IfDefined  !xmlNamespace.UnlessDefined)  { nsMgr.AddNamespace(xmlNamespace.Prefix, xmlNamespace.Uri); } string s = 
xd.SelectSingleNode(xPath, nsMgr).Value; return s; } [Function(get-ns)] public static XmlNamespace GetNamespace(string prefix, string uri) {

 XmlNamespace xn = new XmlNamespace(); xn.Prefix = prefix; xn.Uri = uri; return xn; }BTW, I couldn't get your example of a namespace working. It kept complaining about the version number in the preprocessor. I copied the one from the NAnt help which worked ok.
On 30/01/06, Martin Aliger 
[EMAIL PROTECTED] wrote:
Hello,I like it very much. Expecially functions. Bad luck I personally neednamespace support, since mine xmls have some namespace in it. And evendefault namespace needs specification in xpaths :-(
Maybe there could be some elegant way how to pass namespace mapping into
functions. New type come to my mind. It could be elegant perhaps.btw: does nant functions support overloading and/or default parameter value?bool xml::value-exists (string xmlFile, string xPath,
NamespaceMap nsMap = null)===Here is typical use of namespace map (taken from my real script):xmlpeekfile=${prjconfig}
xpath=x:Project/x:ExeNameproperty=newexefailonerror=true
failonnonode=falsenamespacesnamespace
prefix=x uri=http://www.gordic.cz/shared/project-config/v_1.0.0.0
//namespaces
/xmlpeekAnd sample xml file is here (changed to protect innocent):?xml version=1.0 encoding=utf-8?Project xmlns=

http://www.gordic.cz/shared/project-config/v_1.0.0.0Namefoo/NameDescriptionfoobar/DescriptionExeNamefootest/ExeName/Project

===I missed xml-foreach once too, but nowadays I do not need it. Still it couldbe worth addition to NAnt(Contrib) tasks!Martin Aliger -Original Message- From: 

[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
] On Behalf Of John Ludlow Sent: Tuesday, January 24, 2006 7:19 PM
 To: nant-developers@lists.sourceforge.net; 
nantcontrib-developer@lists.sourceforge.net
 Subject: [nant-dev] New XML tasks and functions Hi, there Recently I mentioned on the NAnt Dev list that I have been working on XML-handling functionality.I've got further than
 I had last time, so I thought about summarising what I've done here (I'm also happy to share the code and/or binaries, so if you want either of these to check it out for yourself, just email me at 
[EMAIL PROTECTED]).I've put my code into an assembly, tested it, and am currently contemplating
 writing some unit tests for it. Before I go through that, though, I wanted to get some
 feedback and a better idea of what people thought of this. This is what I have so far: Functions === bool xml::value-exists (string xmlFile, string xPath)
 -- --- Tests whether a specified xpath query returns a value.If this gets a NullReferenceException (usually means an XML
 value doesn't exist). string xml::get-value (string xmlFile, string xPath) -- - Gets a value returned by an XPath query.Throws an error if
 the node specified in the xpath is not found.Duplicates some of xmlpeek's functionality, but enables you to use ${x} syntax to get an xml value.This fits in with the idea that being able to use this
 functionality is nicer if all you want is information. However, it does not support namespaces like xmlpeek does. string xml::get-value-without-failing (string xmlFile, string xPath) --
 - Gets a value returned by an XPath query.As above, but does not an error if the node specified in the XPath is not found, instead returning a blank string.

 string xml::get-xml (string xmlFile, string xPath) Gets the InnerXml property of an XML