Hello,
DocumentHelper.createElement(String) uses String parameter as local
name. I don't know why it acts so strange with colon, it may be bug in
dom4j. But you probably want something like this:

Element newElement =
DocumentHelper.createElement(QName.get("NET:link",
"http://NET-namespace-URI";)).
addAttribute(QName.get("xlink:href", "http://xlink-namespace-URI";),
"#"+tempo.get(i).toString());

Or you can use other variants of QName.get(...) methods.

Best regards

Filip Jirsák



2010/8/10  <fr...@gmx.net>:
> Hello Filip,
>
> thanks for the suggestion, I tried it but it didn't work, now it leaves out 
> the namespace completely but the element and attribute isn't copied twice as 
> well, which is good. Something between my two "solutions" would be great.
>
> Anyway, here are some parts of code:
>
> Maybe it could be important to show how I get to the right position in the 
> XML data:
> [JAVA]
> while(roadIter.hasNext()){
>  roadid=(Attribute)roadIter.next();
>  for (int i=0;i < tempo.size();i++){                           
> if(roadid.getText().toString().equalsIgnoreCase(tempo.get(i).toString().replaceAll("_.*$",
>  "")))
> [/JAVA]
>
> Then I tried to insert the new element with an attribute like that:
>
> This is the first code I tried with the result as described yesterday.
> (<NET:NET:link xmlns:NET="" xmlns:xlink="" xlink:xlink:href="..."/>)
>
> [JAVA]
> Element newElement = DocumentHelper.createElement("NET:link").
> addAttribute("xlink:href", "#"+tempo.get(i).toString());
> roadid.getParent().content().add(4, newElement);
> [/JAVA]
>
> This is your suggestion. I left out the namespaces but then they are also 
> missing in the final XML
> (<link xmlns="" href="..."/>)
>
> [JAVA]
> Element newElement = DocumentHelper.createElement("link").              
> addAttribute("href", "#"+tempo.get(i).toString());
> roadid.getParent().content().add(4, newElement);
> [/JAVA]
>
> I also added the namespace to the element and attribute  with 
> [JAVA].addNamespace(the Namespace)[/JAVA]. But it didn't work as well.
>
> And here is the code snippet to transform the data:
> [JAVA]
> javax.xml.transform.TransformerFactory tfactory=        
> javax.xml.transform.TransformerFactory.newInstance();
> javax.xml.transform.Transformer transformer=                            
> tfactory.newTransformer(new javax.xml.transform.stream.StreamSource(new 
> java.io.File(xslfinal)));
> transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //für Pritty-Print;
> transformer.setURIResolver(null);
> transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount";, 
> "2"); //für Pritty-Print
>
> DocumentSource source = new DocumentSource (doc);
> DocumentResult result = new DocumentResult();
> transformer.transform(source, result);
> [/JAVA]
> I think it's just the "ordinary" way to do it, so I hope there is no mistake 
> in it.
>
> If you need some more code, just give me a hint.
>
> Thanks and best regards,
> André
>
>
> -------- Original-Nachricht --------
>> Datum: Tue, 10 Aug 2010 09:05:19 +0200
>> Von: "Filip Jirsák" <fi...@jirsak.org>
>> An: fr...@gmx.net
>> CC: dom4j-user@lists.sourceforge.net
>> Betreff: Re: [dom4j-user] sibiling node/XSL Transformation
>
>> Hello,
>> I think there is problem with element names. You probably insert
>> element with name "NET:link" in namespace with prefix "NET". You
>> should instead use only "link" name. The same with attribute
>> "link:href" instead of "href". Be careful of different methods for
>> creating elements or QNames - some of them use only local part of
>> element name and namespace with prefix is passed on as the second
>> parameter, another use full name of element (ns-prefix:local-name) and
>> only namespace URI is passed on as the second parameter. Could you
>> post part of the code where you create new elements?
>>
>> Best regards,
>>
>> Filip Jirsák
>>
>>
>>
>> 2010/8/9  <fr...@gmx.net>:
>> > Hello,
>> >
>> > @Filip:,
>> > thanks a lot, it works now.
>> >
>> > But now I've got the next problem. I try to merge two GML-Files with an
>> XSL Stylesheet in JAVA. It worked quite well until I insert the new
>> Elements.
>> >
>> > Now I've got the problem that I got an non-valid XML because of this
>> line:
>> > <NET:NET:link xmlns:NET="" xmlns:xlink="" xlink:xlink:href="..."/>
>> >
>> > It should look like that:
>> > <NET:link xlink:href="..."/>
>> >
>> > This only happens with the new insert elements.
>> >
>> > I suppose this might be a namespace problem, so I tried to remove the
>> namespace out of the XSL Stylesheet or insert it in the new Element by "add
>> Namespace". But it doesn't work.
>> >
>> > I'm a little bit surprised about the fact, that the same transformation
>> worked on a manually task with Altova XML Spy which I tried. But in JAVA it
>> failed.
>> >
>> > Does anyone know about this problem and know how to solve it?
>> > Maybe it would work just to ignore the namespaces - but I don't know if
>> and how this is possible with DOM4J
>> >
>> > Thanks and Best regards,
>> > André
>> >
>> >
>> > -------- Original-Nachricht --------
>> >> Datum: Wed, 4 Aug 2010 13:39:34 +0200
>> >> Von: "Filip Jirsák" <fi...@jirsak.org>
>> >> An: fr...@gmx.net
>> >> CC: "dom4j-user@lists.sourceforge.net"
>> <dom4j-user@lists.sourceforge.net>
>> >> Betreff: Re: [dom4j-user] sibiling node
>> >
>> >> Hello,
>> >> I think you can do this. Try this:
>> >>
>> >> Element featureElement = document.getRootelement();
>> >> Element newElement = DocumentHelper.createElement("new-element");
>> >> featureElement.content().add(4, newElement);
>> >>
>> >> Best regards
>> >>
>> >> Filip Jirsák
>> >>
>> >>
>> >>
>> >> 2010/8/4  <fr...@gmx.net>:
>> >> > Hello,
>> >> >
>> >> > is there any possibility to insert an sibiling node in DOM4J?
>> >> >
>> >> > I've got an XML like that:
>> >> >
>> >> > <feature>
>> >> >  <Element Level 1>
>> >> >  <Element Level 2/>
>> >> >  </Element Level 1>
>> >> >  <Element Level 1/>
>> >> >  <here I like to insert my new Element>
>> >> >  <Element Level 1/>
>> >> > [...]
>> >> > </feature>
>> >> >
>> >> > So I need a possibility to insert an Element on this exact position
>> but
>> >> I can't find a solution.
>> >> >
>> >> > I can attach an Element at the beginning and the end of the
>> >> <feature>-Container and also as child-Element to an spezific Element in
>> the XML. But I
>> >> can't find a way to insert it between two sibilings.
>> >> >
>> >> > Does anyone know a solution and might even give some code which could
>> be
>> >> helpful?
>> >> >
>> >> > Thanks and best regards,
>> >> > André
>> >> > --
>> >> > GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
>> >> > Bis zu 150 EUR Startguthaben inklusive!
>> http://portal.gmx.net/de/go/dsl
>> >> >
>> >> >
>> >>
>> ------------------------------------------------------------------------------
>> >> > The Palm PDK Hot Apps Program offers developers who use the
>> >> > Plug-In Development Kit to bring their C/C++ apps to Palm for a share
>> >> > of $1 Million in cash or HP Products. Visit us here for more details:
>> >> > http://p.sf.net/sfu/dev2dev-palm
>> >> > _______________________________________________
>> >> > dom4j-user mailing list
>> >> > dom4j-user@lists.sourceforge.net
>> >> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
>> >> >
>> >>
>> >>
>> ------------------------------------------------------------------------------
>> >> The Palm PDK Hot Apps Program offers developers who use the
>> >> Plug-In Development Kit to bring their C/C++ apps to Palm for a share
>> >> of $1 Million in cash or HP Products. Visit us here for more details:
>> >> http://p.sf.net/sfu/dev2dev-palm
>> >> _______________________________________________
>> >> dom4j-user mailing list
>> >> dom4j-user@lists.sourceforge.net
>> >> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>> >
>> >
>> > --
>> > Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
>> > Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
>> >
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by
>>
>> Make an app they can't live without
>> Enter the BlackBerry Developer Challenge
>> http://p.sf.net/sfu/RIM-dev2dev
>> _______________________________________________
>> dom4j-user mailing list
>> dom4j-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
> --
> Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!
> Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
>

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to