[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: embedded html


org.jdom.element.addcontent
Title: embedded html
hey,
 
a while ago i posted this problem. One week later, the problem is still not solved... and i don't know why. Does anyone know an answer to this problem?
what i try to do is adding an element to an already existing element of a document but i gives an error...when adding the element..
 
org.jdom.IllegalAddException: The element "root" could not be added as a child of "test": The element already has an existing parent (the document root)
 
code and error are included...
 
any help welcome,
thanks bart
 
Code:
// Java imports
import java.io.File;
import java.io.StringReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.List;
 
// JDOM imports
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.input.DOMBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.Element;
import org.jdom.input.DefaultJDOMFactory;
 
public class SAXtoJDOM {
 
    public static void main(String[] args) {
       
  try {
   SAXtoJDOM s2j = new SAXtoJDOM();
   Document doc1 = s2j.createDocumentFromString("<root>tested before link <SITELINK><a href='test.html'>tests</a> </SITELINK>after link</root>");
   Document doc2 = s2j.createDocumentFromFile("d:/test.xml");
          
            // Output the document to System.out
            XMLOutputter outputter = new XMLOutputter();
   
   System.out.println("\n\n----------------------------- ROOT ELEMENT DUMP ");
   Element rootEl = doc1.getRootElement();
   
   Element testEl = doc2.getRootElement();
   testEl.addContent(rootEl);
   
   System.out.println("**** " + rootEl.getParent());
   
   DefaultJDOMFactory factory = new DefaultJDOMFactory();
   Element testElement = factory.element("testChild");
   rootEl.addContent(testElement);
   
   List rootElContent = rootEl.getContent();
   for (int i = 0; i < rootElContent.size(); i++) {
    System.out.println("Element " + i + " = " + rootElContent.get(i));
   }
      
   System.out.println("\n\n----------------------------- FROM STRING");
            outputter.output(doc1, System.out);
   
   System.out.println("\n\n----------------------------- FROM FILE");
   outputter.output(doc2, System.out);
   
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
 
 public Document createDocumentFromString(String xmlString) throws JDOMException {
 
  StringReader sr = new StringReader(xmlString);
  SAXBuilder builder = new SAXBuilder();
  return builder.build(sr);
 }
 
public Document createDocumentFromFile(String filePath) throws JDOMException {
 
  File file = new File(filePath);
        SAXBuilder builder = new SAXBuilder();
  return builder.build(file);
 }
}
 
Output:
 

----------------------------- ROOT ELEMENT DUMP

org.jdom.IllegalAddException: The element "root" could not be added as a child of "test": The element already has an existing parent (the document root)

at org.jdom.Element.addContent(Element.java:1172)

at SAXtoJDOM.main(SAXtoJDOM.java, Compiled Code)

Process Exit...

 

 -----Original Message-----
From: Julian Reschke [mailto:julian.reschke@g...]
Sent: Thursday, December 20, 2001 10:48 AM
To: Bart.Boogaerts@A...; xml-dev@l...
Subject: RE: embedded html

Bart,
 
if you wan't your XML processor to treat the HTML as markup, not as text, you'll have to *tell* it that it's markup. So,
 
a) wrap the text into a container tag like <p>
b) parse the string into a JDOM
c) move all child nodes to your BODYTEXT element.
 
 
-----Original Message-----
From: Bart.Boogaerts@A... [mailto:Bart.Boogaerts@A...]
Sent: Thursday, December 20, 2001 11:36 AM
To: xml-dev@l...
Subject: RE: embedded html

Forgot to tell that i was using xmlOutputter from org.jdom
and that in our dtd, these <a> elements are declared, so no validation faults are given...
we just add all elements to the document structure, except this one (included in the text) but is a valid xml tag...
 
thanks, bart
-----Original Message-----
From: Bart.Boogaerts@A... [mailto:Bart.Boogaerts@A...]
Sent: Thursday, December 20, 2001 10:14 AM
To: xml-dev@l...
Subject: embedded html

hey,

on one of my projects, i'm working with Jdom (old version jan. 2000) to parse xml (when validating)
If i want to use html tags between xml tags, the tags are replaced by "&lt;" or "&gt;"...

example:

<BODYTEXT>this is just text with a link<a href="link.html">text for link</a>text goes on</BODYTEXT>

the text between the bodytext is just text, coming right out of the database. When getting the text from the database, everything is just fine but when adding this text to the document (while constructing the doc) and parsing it we get the "<" signs replaced by "&lt;" etc.

How do i avoid the replacing of these tags without having to extract the link data of the text and putting it between xml tags?

regards,bart


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.