Hey there everyone.

I wondered if anyone could help me out with writing a simple program that checks through blocks of HTML code replacing specific sections of code within each block of 3 <div>'s. It is basically to make my life easier when I have to edit a website, otherwise i'm editing all the numbers manually and this can take ages! :P I know it would be easier to use a database or something along those lines. But we don't really have that option.

The program needs to focus on this bit, checking to make sure the numbers are correct and if not replacing them with the correct number.

<div class="js-image size-2" style="height: 143px; left:0px;">

Checking to make sure that is correct. Then this:

<div class="js-image size-2" style="height: 143px; left:135px;">

Then this:

<div class="js-image size-2" style="height: 143px; left:270px;">

In the next block of 3 it would need to check:

<div class="js-image size-2" style="height: 143px; left:0px; top: 154px;">
<div class="js-image size-2" style="height: 143px; left:135px; top: 154px;">	
<div class="js-image size-2" style="height: 143px; left:270px; top: 154px;">

Then in the next block:

<div class="js-image size-2" style="height: 143px; left:0px; top: 308px;">

etc etc. Until everything within the document is correctly incremented in order.

My Java is pretty rusty so if anyone can give me a starting point it would be great. If everyone wants to do it for me, or if you have a better solution or simpler language to do it in then thats great to.

Entire example of a block of code is below.

Thanks to anyone that fancies helping.

<div id="js-container">
	<!-- row start -->
				
			<div class="js-image size-2" style="height: 143px; left:0px;">		
				<a href="url" target="_parent"><img class="js-small-image" src="img-url" /></a>
				<div class="js-small-caption">
					<span>Jean Cocteau</span>
				</div>
				<div class="js-overlay-caption-content">

					<h4>Jean Cocteau</h4>
					<p>&nbsp;</p>
					<p>
						Author's signature and unusual drawing on book... <a href="url" target="_parent"><br /><br />Read more &raquo;</a>
					</p>
				</div>
			</div>
		
				
			<div class="js-image size-2" style="height: 143px; left:135px;">		
				<a href="url" target="_parent"><img class="js-small-image" src="img-url" /></a>

				<div class="js-small-caption">
					<span>Leonard Cohen</span>
				</div>
				<div class="js-overlay-caption-content">
					<h4>Leonard Cohen</h4>
					<p>&nbsp;</p>
					<p>
						Reclusive musician's autograph... <a href="url" target="_parent"><br /><br />Read more &raquo;</a>

					</p>
				</div>
			</div>
		
				
			<div class="js-image size-2" style="height: 143px; left:270px;">		
				<a href="url" target="_parent"><img class="js-small-image" src="img-url" /></a>
				<div class="js-small-caption">
					<span>Charles Dickens</span>
				</div>
				<div class="js-overlay-caption-content">

					<h4>Charles Dickens</h4>
					<p>&nbsp;</p>
					<p>
						A Coutts bank cheque dated March 25 1861... <a href="url" target="_parent"><br /><br />Read more &raquo;</a>

					</p>
				</div>
			</div>
			
		<!-- row end -->

		<!-- row start -->

Hi Ranek
I see no one has replied yet. Maybe that's because. like me, they can't understand your statement of requirement? I've read it twice, and I still don't know what it is you want to do. Maybe it would help to post a short before/after example showing what was changed and why?

another reason would be that it's mainly a request for code.
have you tried to implement it yourself? do you have enough background in Java to try it yourself?

I think so. However, a simple solution to this is to get a text editor that can find & replace a string... Why do you need a java program if you already have the tool? By the way, don't use Notepad because it .... Let say it is not a qualify text editor...

I'm sorry. I do tend to over complicate things a bit.

A page on my website contains stock item images arranged in alphabetical order, and placed by absolute positioning at specific points on a web page.

When I add or remove a stock item I then have to change the left:#px and top:#px values on all of the <divs> below the one I have inserted. To put them in the correct order.

The left:#px starts in a sequence of 0, 135, 270, 0, 135, 270..
The top:#px is a sequence of 0, 0, 0, 154, 154, 154, 308, 308,308..

So the program needs to go through the code and make sure that the numbers for left:#px and top:#px. Are set in that sequence.

Does this make anymore sense? :D

@Stultuske & Taywin:

I haven't tried to implement it myself as i'm not sure where to begin. However if someone could offer a starting point I would be happy to take it and work at it from there. My Java is pretty poor, I did a module of Java as part of my degree but i was never very good.

I don't think its as simple as using find and replace Taywin, because I want the numbers to increment in sequence, and say if I insert 3 stock items, one near the beginning, one near the end and one in the middle it will completely change the sequence.

Sorry if this post offends anyone, its not supposed to be a "give me the code" post. I'd just like a bit of advice about the method in which to do it, then i'll try it myself

Thanks

There could also already be a program that could do it for me, so if i'm being dumb and don't need to make it myself let me know :)

So, you need to search through the file. Each time you encounter a "<div>" you need to find the following "left:#px" and "top:#px" values and set them to the sequences you posted, regardless of whatever they may have been before.
Is that correct?
I suspect that may be a bit hard for a simple editor, although it may be possible if you use one with decent macro capabilities. Equally I think it's too hard for a regex, although I'm constantly amazed by what experts can do with regexes.
On the other hand this wouldn't be a hard program in Java (or any other proper language) - read a file, find bits of fixed text, replace numeric strings with values from a pre-defined array, write it to a file..

Yeah thats exactly what I want it to do.

Now that you've set it out like that:

read a file, find bits of fixed text, replace numeric strings with values from a pre-defined array, write it to a file..

It seems a lot simpler!

I'll go away and give it a go myself. I'll provide an update when I inevitably get stuck! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.