Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > storing the text of an HTML page

Reply
Thread Tools

storing the text of an HTML page

 
 
JCD
Guest
Posts: n/a
 
      05-28-2008
Hello.
In my application, I need to store the text of an HTML page.
For example:
<!DOCTYPE ht....
....
....
</HTML>
I modify it after, to create a new HTML page that I open in a web
browser.
I would like to store this text in my application without creating a
file on the hard disc.
I want to keep line feeds and there are many " in the text.
Is there a way of storing this text and how?
thank you.
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      05-28-2008
JCD <> writes:
>Is there a way of storing this text and how?


Yes, usually as an object of any class implementing
java.lang.CharSequence or as an array of code points.

Text also can be stored as an object of java.lang.BigDecimal
or so, but this would be unusual and more difficult to use.

 
Reply With Quote
 
 
 
 
Lord Zoltar
Guest
Posts: n/a
 
      05-28-2008
On May 28, 1:40*pm, JCD <jcd.n...@club-internet.fr> wrote:
> Hello.
> In my application, I need to store the text of an HTML page.
> For example:
> <!DOCTYPE ht....
> ...
> ...
> </HTML>
> I modify it after, to create a new HTML page that I open in a web
> browser.
> I would like to store this text in my application without creating a
> file on the hard disc.
> I want to keep line feeds and there are many " in the text.
> Is there a way of storing this text and how?
> thank you.


Why do you think you need to keep it in a file on the hard disc?
Normally, getting HTML data from an internet source would result in
the HTML data being stored into some sort of in-memory structure, such
as as String. Writing that to disc seems like it would be extra work.
You say you have to modify the HTML data... what sort of
modifications? If they're fairly simple, you could just use regular
expressions to find/replace substrings in the big string. For
complicated modifications, maybe build a tree out of the HTML nodes,
modify the tree, then turn your tree back into a string.
 
Reply With Quote
 
Donkey Hot
Guest
Posts: n/a
 
      05-28-2008
Lord Zoltar <> wrote in news:c1675928-4d26-4753-af9b-
:

> On May 28, 1:40*pm, JCD <jcd.n...@club-internet.fr> wrote:
>> Hello.
>> In my application, I need to store the text of an HTML page.
>> For example:
>> <!DOCTYPE ht....
>> ...
>> ...
>> </HTML>
>> I modify it after, to create a new HTML page that I open in a web
>> browser.
>> I would like to store this text in my application without creating a
>> file on the hard disc.
>> I want to keep line feeds and there are many " in the text.
>> Is there a way of storing this text and how?
>> thank you.

>
> Why do you think you need to keep it in a file on the hard disc?
> Normally, getting HTML data from an internet source would result in
> the HTML data being stored into some sort of in-memory structure, such
> as as String. Writing that to disc seems like it would be extra work.
> You say you have to modify the HTML data... what sort of
> modifications? If they're fairly simple, you could just use regular
> expressions to find/replace substrings in the big string. For
> complicated modifications, maybe build a tree out of the HTML nodes,
> modify the tree, then turn your tree back into a string.
>


1st thing that came to my mind, is that he wants to create a man-in-the-
middle, editing html between a website and a browser. And not wanting to
leave traces on the disk, so that some kind of an antivirus might be able
scan it.

Of course thats funny, but it popped to my mind.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-28-2008
On Wed, 28 May 2008 10:40:36 -0700 (PDT), JCD
<> wrote, quoted or indirectly quoted someone
who said :

>I would like to store this text in my application without creating a
>file on the hard disc.


The two most likely ways are with a simple giant String and a parse
tree.

Unfortunately most of the stuff out on the web is malformed. Usually
the only stuff you can fully parse is stuff you validated yourself.

see http://mindprod.com/jgloss/parser.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      05-28-2008
JCD wrote:

> I would like to store this text in my application without creating a
> file on the hard disc.


A file on disc probably would be the best way. Look into JSP.

Absent that, no, I don't know of any type of convenient storage
mechanism. A resource file would be good, but it's basically a file on
disc anyway. A property would likely be wildly inappropriate, unless
the string you are storing is very short.
 
Reply With Quote
 
JCD
Guest
Posts: n/a
 
      05-29-2008
Actually, I don't want to get HTML data from an internet source : I
already have the source code and the modifications are very simple : I
only have to change a few lines that depend on the results of my
application. I don't need to create a tree or a parser: I want to
store in my java code source this HTML text. The problem is that the
text is very long and it contains many " and many line feeds.
Of course, I could create for example an array containing each line of
the HTML page but it would be too long to write.
Is there a way of storing a giant String with " and line feeds?
 
Reply With Quote
 
Philipp
Guest
Posts: n/a
 
      05-30-2008
JCD wrote:
> Actually, I don't want to get HTML data from an internet source : I
> already have the source code and the modifications are very simple : I
> only have to change a few lines that depend on the results of my
> application. I don't need to create a tree or a parser: I want to
> store in my java code source this HTML text. The problem is that the
> text is very long and it contains many " and many line feeds.
> Of course, I could create for example an array containing each line of
> the HTML page but it would be too long to write.
> Is there a way of storing a giant String with " and line feeds?


You can store " and line feeds in a String object. No problem there.
Phil
 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      05-30-2008
Philipp wrote:
> JCD wrote:
>> Actually, I don't want to get HTML data from an internet source : I
>> already have the source code and the modifications are very simple : I
>> only have to change a few lines that depend on the results of my
>> application. I don't need to create a tree or a parser: I want to
>> store in my java code source this HTML text. The problem is that the
>> text is very long and it contains many " and many line feeds.
>> Of course, I could create for example an array containing each line of
>> the HTML page but it would be too long to write.
>> Is there a way of storing a giant String with " and line feeds?

>
> You can store " and line feeds in a String object. No problem there.
> Phil


Java string constants cannot span multiple lines. Java has no equivalent
of the "here document" in Shell or Perl. Sometimes I miss these features.

static final String HTML = "
<html>
<head>
...
</body>
</html>
";

String html = <<END;
<html>
<head>
...
</body>
</html>
END

The Java-ish solution seems to be properties files.

--
RGB
 
Reply With Quote
 
Philipp
Guest
Posts: n/a
 
      05-30-2008
RedGrittyBrick wrote:
> Philipp wrote:
>> JCD wrote:
>>> Actually, I don't want to get HTML data from an internet source : I
>>> already have the source code and the modifications are very simple : I
>>> only have to change a few lines that depend on the results of my
>>> application. I don't need to create a tree or a parser: I want to
>>> store in my java code source this HTML text. The problem is that the
>>> text is very long and it contains many " and many line feeds.
>>> Of course, I could create for example an array containing each line of
>>> the HTML page but it would be too long to write.
>>> Is there a way of storing a giant String with " and line feeds?

>>
>> You can store " and line feeds in a String object. No problem there.

>
> Java string constants cannot span multiple lines.


Yep. I didn't understand the OP's request correctly.

At this point I can only recommend to use a decent text editor (eg. try
textpad.com) and replace all newline characters by \n (or its
crossplatform equivalent) and every " by a \"

For example,
String s = "hello \n\"world\"";

Phil
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
storing html page with images in a database SRM ASP .Net 1 01-09-2009 05:14 AM
User Images: Storing in Files VS Storing in Database Jonathan Wood ASP .Net 1 06-02-2008 05:56 PM
HTML Code embedded within HTML Page as Text =?Utf-8?B?UGF1bA==?= ASP .Net 5 11-07-2007 05:32 PM
storing pointer vs storing object toton C++ 11 10-13-2006 11:08 AM
how to redirect to a frames-based html page and load the right html when coming from an ASP.NET page Mark Kamoski ASP .Net 1 08-13-2003 05:51 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57