Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Fwd: Replacing an element with another element

Fwd: Replacing an element with another element

2007-02-26       - By Mark Drew

 Back
Hi there
first time poster so go easy on me :)

I have a document, that I want to replace an Element with another  
Element (from a different document). I have tried a number of things  
but dont seem to be able to get it right.
(A little more background, I have a document tree, when you select an  
Element, you can see the whole Element's text in a text field that  
you can edit it. When you are done editing that Element, it creates a  
new document with just that Element, I now want to replace the  
original element with that text)

Any ideas?

Here is what I have so far...
StringBuffer StringBuffer1 = new StringBuffer(editedElementText);
              ByteArrayInputStream Bis1;
              try {
                Bis1 = new ByteArrayInputStream(StringBuffer1.toString
().getBytes("UTF-8 (See http://UTF-8.ora-code.com)"));
                LineNumberSAXBuilder builder = new LineNumberSAXBuilder();
                builder.setValidation(false);
                Document document = builder.build(Bis1);
                Element content = (Element)document.getRootElement().clone();
                selNode.setElement(content); //the orignial node
                XMLOutputter outputter = new XMLOutputter();
                String modDocument = outputter.outputString(selNode.getElement
().getDocument());
                System.out.println(modDocument);
             
              }
              ....

               
but it doesnt seem to change the original document.

Many thanks in advance

Mark Drew


<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line
-break: after-white-space; "><DIV>Hi there<DIV>first time poster so go easy on
me :)</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I have a
document, that I want to replace an Element with another Element (from a
different document). I have tried a number of things but dont seem to be able
to get it right.?</DIV><DIV>(A little more background, I have a document tree,
when you select an Element, you can see the whole Element's text in a text
field that you can edit it. When you are done editing that Element, it creates
a new document with just that Element, I now want to replace the original
element with that text)</DIV><DIV><BR class="khtml-block-placeholder"></DIV>
<DIV>Any ideas?</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Here is
what I have so far...</DIV><DIV style="margin-top: 0px; margin-right: 0px;
margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span" face=
"Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;"
>StringBuffer StringBuffer1 = </SPAN></FONT><FONT class="Apple-style-span" color
="#7F0055" face="Monaco" size="3"><SPAN class="Apple-style-span" style="font
-size: 11px;">new</SPAN></FONT><FONT class="Apple-style-span" face="Monaco" size
="3"><SPAN class="Apple-style-span" style="font-size: 11px;"> StringBuffer(<FONT
class="Apple-style-span" color="#0000C0">editedElementText</FONT></SPAN></FONT>
<FONT class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style
-span" style="font-size: 11px;">);</SPAN></FONT></DIV><DIV style="margin-top:
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white
-space:pre">   </SPAN><FONT class="Apple-style-span" face="Monaco" size="3"><SPAN
class="Apple-style-span" style="font-size: 11px;">ByteArrayInputStream Bis1;<
/SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom
: 0px; margin-left: 0px; "><SPAN class="Apple-tab-span" style="white-space:pre">
  </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class
="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><FONT class="Apple-style
-span" color="#7F0055" face="Monaco" size="3"><SPAN class="Apple-style-span"
style="font-size: 11px;">try</SPAN></FONT><FONT class="Apple-style-span" face=
"Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;"> {<
/SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom
: 0px; margin-left: 0px; "><SPAN class="Apple-tab-span" style="white-space:pre">
  </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class
="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><FONT class="Apple-style-span" face=
"Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;">Bis1 =
</SPAN></FONT><FONT class="Apple-style-span" color="#7F0055" face="Monaco" size
="3"><SPAN class="Apple-style-span" style="font-size: 11px;">new</SPAN></FONT>
<FONT class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style
-span" style="font-size: 11px;"> ByteArrayInputStream(StringBuffer1.toString()
.getBytes(</SPAN></FONT><FONT class="Apple-style-span" color="#2A00FF" face=
"Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;">"UTF-8 (See http://UTF-8.ora-code.com)
"</SPAN></FONT><FONT class="Apple-style-span" face="Monaco" size="3"><SPAN class
="Apple-style-span" style="font-size: 11px;">));</SPAN></FONT></DIV><DIV style=
"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
<SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple
-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style=
"white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">  
</SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><FONT class="Apple-style-span" face="Monaco" size="3"><SPAN class=
"Apple-style-span" style="font-size: 11px;">LineNumberSAXBuilder builder = <
/SPAN></FONT><FONT class="Apple-style-span" color="#7F0055" face="Monaco" size=
"3"><SPAN class="Apple-style-span" style="font-size: 11px;">new</SPAN></FONT>
<FONT class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style
-span" style="font-size: 11px;"> LineNumberSAXBuilder();</SPAN></FONT></DIV><DIV
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px
; "><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white
-space:pre">   </SPAN><FONT class="Apple-style-span" face="Monaco" size="3"><SPAN
class="Apple-style-span" style="font-size: 11px;">builder.setValidation(</SPAN>
</FONT><FONT class="Apple-style-span" color="#7F0055" face="Monaco" size="3">
<SPAN class="Apple-style-span" style="font-size: 11px;">false</SPAN></FONT><FONT
class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style-span"
style="font-size: 11px;">);</SPAN></FONT></DIV><DIV style="margin-top: 0px;
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple
-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style=
"white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">  
</SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><FONT
class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style-span"
style="font-size: 11px;">Document document = builder.build(Bis1);</SPAN></FONT>
</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin
-left: 0px; "><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white
-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN
><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple
-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style=
"white-space:pre">   </SPAN><FONT class="Apple-style-span" face="Monaco" size="3">
<SPAN class="Apple-style-span" style="font-size: 11px;">Element content =
(Element)document.getRootElement().clone();</SPAN></FONT></DIV><DIV style=
"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
<SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple
-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style=
"white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">  
</SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><FONT class="Apple-style-span" color="#0000C0" face="Monaco" size=
"3"><SPAN class="Apple-style-span" style="font-size: 11px;">selNode</SPAN></FONT
><FONT class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style
-span" style="font-size: 11px;">.setElement(content); //the orignial node</SPAN>
</FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px;
margin-left: 0px; "><SPAN class="Apple-tab-span" style="white-space:pre">   <
/SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><FONT class="Apple-style-span" face=
"Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;"
>XMLOutputter outputter = </SPAN></FONT><FONT class="Apple-style-span" color="
#7F0055" face="Monaco" size="3"><SPAN class="Apple-style-span" style="font-size:
11px;">new</SPAN></FONT><FONT class="Apple-style-span" face="Monaco" size="3">
<SPAN class="Apple-style-span" style="font-size: 11px;"> XMLOutputter();</SPAN><
/FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px;
margin-left: 0px; "><SPAN class="Apple-tab-span" style="white-space:pre">   <
/SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><FONT class="Apple-style-span" face=
"Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;">String
modDocument = outputter.outputString(</SPAN></FONT><FONT class="Apple-style
-span" color="#0000C0" face="Monaco" size="3"><SPAN class="Apple-style-span"
style="font-size: 11px;">selNode</SPAN></FONT><FONT class="Apple-style-span"
face="Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;">
.getElement().getDocument());</SPAN></FONT></DIV><DIV style="margin-top: 0px;
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple
-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style=
"white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">  
</SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><FONT
class="Apple-style-span" face="Monaco" size="3"><SPAN class="Apple-style-span"
style="font-size: 11px;">System.</SPAN></FONT><FONT class="Apple-style-span"
color="#0000C0" face="Monaco" size="3"><SPAN class="Apple-style-span" style=
"font-size: 11px;">out</SPAN></FONT><FONT class="Apple-style-span" face="Monaco"
size="3"><SPAN class="Apple-style-span" style="font-size: 11px;">.println
(modDocument);</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px
; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><SPAN class="Apple
-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style=
"white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">  
</SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><BR><SPAN class="Apple-tab-span" style="white-space:pre">               <
/SPAN>}</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px;
margin-left: 0px; min-height: 14px; "><SPAN class="Apple-tab-span" style="white
-space:pre">               </SPAN>....</DIV><DIV style="margin-top: 0px; margin-right:
0px; margin-bottom: 0px; margin-left: 0px; "><FONT class="Apple-style-span"
face="Monaco" size="3"><SPAN class="Apple-style-span" style="font-size: 11px;">
<BR class="khtml-block-placeholder"></SPAN></FONT></DIV><DIV style="margin-top:
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px;
"><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class=
"Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span"
style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space
:pre">   </SPAN><SPAN class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN
class="Apple-tab-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab
-span" style="white-space:pre">   </SPAN><SPAN class="Apple-tab-span" style="white
-space:pre">   </SPAN><BR>but it doesnt seem to change the original document.</DIV
><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left
: 0px; min-height: 14px; "><BR class="khtml-block-placeholder"></DIV><DIV style=
"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min
-height: 14px; ">Many thanks in advance</DIV><DIV style="margin-top: 0px; margin
-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR class
="khtml-block-placeholder"></DIV><DIV style="margin-top: 0px; margin-right: 0px;
margin-bottom: 0px; margin-left: 0px; min-height: 14px; ">Mark Drew?</DIV></DIV
><BR></BODY></HTML>
__ ____ ____ ____ ____ ____ ____ ____ ____ ____
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.