Mobile app version of vmapp.org
Login or Join
Megan663

: What tool to use to modify HTML file structure I have HTML files with all sharing the same structure. Something like this: Body Table tr1 ... (more

@Megan663

Posted in: #Html #TextEditor #Xml

I have HTML files with all sharing the same structure. Something like this:

Body
Table
tr1
... (more nested tables)
tr2
... (more nested tables)
tr3
td1
... (more nested tables)
td2
tr4 ...


I need to remove td1 table data from all the files. What tool should I use?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Megan663

2 Comments

Sorted by latest first Latest Oldest Best

 

@Fox8124981

JavaScript and the DOM are very quick ways to update any items on a web page. If you understand scripting, it is pretty easy to pick up as it's loosely typed. If there is a unique identifier, or if you have a way of adding one, it's pretty useful. Or you can fetch the table, loop through rows or cells, whichever you prefer, checking each element for evidence that the item needs to be removed, and then you can pluck it right off the DOM tree. JavaScript all the way!

UPDATE

First, you should read this. Don't stop there! MDN has a lot of great information, including reference for many different languages including HTML, the DOM, and Javascript. For an "Idiot's Guide" starting point, you can check out this, but you you should keep in mind that their information is not perfect and they receive a fair amount of discredit from the dev community. However, it is nevertheless a good starting point.

Given your example, you want to get rid of the first cell. I am going to guess for the sake of this example that your table will have an id. So that would look something like this:

var table = document.getElementById('tableID'); //There are other ways to fetch HTML elements, but this is the most direct. It returns a table object.
var rows = table.rows; //Create a variable to store the table rows.
row1 = rows[0]; //Stores the first row in a variable.
row1.deleteCell(0); //Delete the first cell in the first row.


Admittedly, this is a very simplified version. If you are removing cells dynamically, you are probably going to have to collect rows and iterate through them searching for attributes: classes, IDs, etc, and then remove them. If you need help with that, I recommend posting more questions.

I hope this helps!

10% popularity Vote Up Vote Down


 

@Harper822

Actually, there was a StackOverflow question about a similar problem; the most useful of which (and also the least complicated) includes using XSLT to modify your XHTML into another format.
help.hannonhill.com/discussions/how-do-i/269-strip-specific-html-tag-in-xslt
I also found an interesting gem, the HTML Enforcer. DISCLAIMER: I haven't used HTML Enforcer, so use with caution.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme