xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: Arjan Huijzer <huijzer AT gmail.com>
- To: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] CDATA sections
- Date: Wed, 5 Jan 2005 15:59:39 +0100
John,
I am now trying to use your TagSoup parser, but I am running into some
trouble, because TagSoup creates an entire xhtml document. But,
instead, I just want an XML fragment containing the uploaded content.
Is there a way to easily achieve that?
=================================================
import java.io.StringReader;
import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Serializer;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
public class TagSoupTest {
public static void main(String[] args) throws Exception {
// The raw content as supplied by a user
String content = "<h1>title</H1><P>Some Text<ul><li>Item
1<li>Item 2";
// Create a well-formed XML document based on the unparsed
HTML
XMLReader tagsoup = XMLReaderFactory
.createXMLReader("org.ccil.cowan.tagsoup.Parser");
Builder bob = new Builder(tagsoup);
Document doc = bob.build(new StringReader(content));
Serializer serializer = new Serializer(System.out,
"ISO-8859-1");
serializer.setIndent(4);
serializer.setMaxLength(64);
serializer.write(doc);
}
}
This will create the following output:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html version="-//W3C//DTD HTML 4.01 Transitional//EN"
xmlns="http://www.w3.org/1999/xhtml">
<body>
<h1>title</h1>
<p>Some Text</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</body>
</html>
But what I really want is (preferably without namespace):
<h1>title</h1>
<p>Some Text</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Thanks,
Arjan
On Wed, 5 Jan 2005 06:42:46 -0500, John Cowan <jcowan AT reutershealth.com>
wrote:
> Arjan Huijzer scripsit:
>
> > 1. The content of my article would be added by the users that may (or
> > may not) choose to add some HTML to it. But it might very well not be
> > well-formed XML and I do not want to place that restriction on them.
> > So I find mixed content not desirable, because it would mean I have to
> > parse the HTML and create well-formed XHTML from it.
>
> Well, you could use my TagSoup parser for that purpose; it's known to
> work well with XOM. http://www.tagsoup.info .
>
> --
> [W]hen I wrote it I was more than a little John Cowan
> febrile with foodpoisoning from an antique carrot
> jcowan AT reutershealth.com
> that I foolishly ate out of an illjudged faith www.ccil.org/~cowan
> in the benignancy of vegetables. --And Rosta
> www.reutershealth.com
>
-
[XOM-interest] CDATA sections,
Arjan Huijzer, 01/04/2005
- Re: [XOM-interest] CDATA sections, John Cowan, 01/04/2005
- Re: [XOM-interest] CDATA sections, Elliotte Harold, 01/04/2005
- <Possible follow-up(s)>
-
RE: [XOM-interest] CDATA sections,
New, Cecil (GE Trans), 01/04/2005
-
Re: [XOM-interest] CDATA sections,
Elliotte Harold, 01/04/2005
-
Re: [XOM-interest] CDATA sections,
John Cowan, 01/04/2005
- Re: [XOM-interest] CDATA sections, Arjan Huijzer, 01/05/2005
-
Re: [XOM-interest] CDATA sections,
Arjan Huijzer, 01/05/2005
- Re: [XOM-interest] CDATA sections, Elliotte Harold, 01/05/2005
-
Message not available
-
Re: [XOM-interest] CDATA sections,
John Cowan, 01/05/2005
-
Re: [XOM-interest] CDATA sections,
Arjan Huijzer, 01/05/2005
- Re: [XOM-interest] CDATA sections, John Cowan, 01/05/2005
- Re: [XOM-interest] CDATA sections, Arjan Huijzer, 01/05/2005
- Re: [XOM-interest] CDATA sections, John Cowan, 01/05/2005
-
Re: [XOM-interest] CDATA sections,
Arjan Huijzer, 01/05/2005
-
Re: [XOM-interest] CDATA sections,
John Cowan, 01/05/2005
-
Re: [XOM-interest] CDATA sections,
John Cowan, 01/04/2005
-
Re: [XOM-interest] CDATA sections,
Elliotte Harold, 01/04/2005
Archive powered by MHonArc 2.6.24.