You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ross Bleakney <ro...@internationalcontent.com> on 2003/07/01 20:29:33 UTC

Creating new element with JXPath

I would like to create a new element with JXPath (even if an element
with the same name exists). If I try to use JXPathContext.createPath(),
it returns an existing element. For example, if I have the following
XML:

<form>
   <input type="text" id="existing" />
</form>

and I want to add another <input> element, how can I do this?
Thanks,
Ross




Re: Creating new element with JXPath

Posted by Dmitri Plotnikov <dp...@yahoo.com>.
Ross,

If JXPath finds an element that matches the XPath, it simply returns
that element instead of creating a new one. 

You can take one of these two approaches: 
- introduce some distinguising feature for the new element, e.g.
      createPath("/form/input[@id='another']")
- use explicit indexing, e.g.
      createPath("/form/input[2]")

I hope this helps.

- Dmitri


--- Ross Bleakney <ro...@internationalcontent.com> wrote:
> I would like to create a new element with JXPath (even if an element
> with the same name exists). If I try to use
> JXPathContext.createPath(),
> it returns an existing element. For example, if I have the following
> XML:
> 
> <form>
>    <input type="text" id="existing" />
> </form>
> 
> and I want to add another <input> element, how can I do this?
> Thanks,
> Ross
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com