Where does HTML 'id' attribute map to in the DOM?

The Application Programming Interface and the OASIS Open Document Format
Post Reply
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Where does HTML 'id' attribute map to in the DOM?

Post by _savage »

Suppose I have a simple HTML file like so:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="../style/stylesheet.css" type="text/css" rel="stylesheet"/>
  </head>
  <body class="b">
    <p id="p-001" class="par">Content</p>
    <p class="par">Some bla</p>
    <!-- A reference to a paragraph in a neighboring file. -->
    <p id="id=p-003" class="par">…<a href="../text/page-2.html#p-021" class="link">Link</a>…</p>
    …
    <!-- An internal reference to a paragraph in this file. -->
    <p id="id=p-009" class="par">…<a href="#p-001" class="link">Top</a>…</p>
    …
  </body>
</html>
Notice how some paragraphs (and in HTML potentially many/most elements) have an “id” attribute here. The third paragraph then contains a link to a paragraph in a different file.

Loading this file into Office and browsing around its DOM, I am unable to find where the “id” attribute is stored for the paragraph. Not quite sure which interface or service would give me access to that value—if any. Some help would be good, short of digging into the source code for the HTML filter…
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
YODA
Posts: 64
Joined: Fri Aug 10, 2018 4:06 am

Re: Where does HTML 'id' attribute map to in the DOM?

Post by YODA »

I personally would use a dedicated html editor like Blue Griffon available at http://bluegriffon.org/ instead.
Openoffice4.16 on windows 10 Libreoffice Version: 6.1.3.2 (x64)
User avatar
RoryOF
Moderator
Posts: 33646
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Where does HTML 'id' attribute map to in the DOM?

Post by RoryOF »

In an administrative query the OP asked if "he could delete postings that were irrelevant to him".

I replied as follows
You may only delete your own postings, which we discourage, as it is antisocial and contrary to the spirit of the Forum.

If you feel a posting is irrelevant to you simply ignore it; in OO there are often many ways to achieve a given target - your "irelevancy" may be someone else's lifeline.
I agree with YODA that a dedicated HTML editor may be best; OO does not generate good HTML code.
Apache OpenOffice 4.1.13 on Xubuntu 22.04.1 LTS and very infrequently on Win2K/XP
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Where does HTML 'id' attribute map to in the DOM?

Post by _savage »

I wasn’t asking about producing HTML code, but about reading HTML code into Office. To answer the above question, it seems that HTML elements with an `id` attribute produce a bookmark in the DOM.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Villeroy
Volunteer
Posts: 30799
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Where does HTML 'id' attribute map to in the DOM?

Post by Villeroy »

YOU are the developer of your program. Lookup the Open Document Format specification and the content.xml of an example document where you inserted a bookmark.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
bradleyross
Posts: 3
Joined: Thu Aug 29, 2019 7:55 pm

Re: Where does HTML 'id' attribute map to in the DOM?

Post by bradleyross »

If you interested in the DOM and the ECMAScript/JavaScript methods for working with it, I would look at http://www.w3schools.com. No two elements in the same document can have the same id value, and the element is located by using document.getElementById(id_value) ( https://www.w3schools.com/js/js_htmldom_elements.asp ) where id_value is the text string that is the value of the id value of the element. The DOM object for an html element is an instantiation of Element.prototype ( https://www.w3schools.com/jsref/dom_obj_all.asp ) and it has a defined set of methods and properties. However, JavaScript uses weak typing, which means that the relationships between superclasses, subclasses, and instantiations are much looser than in Java. I'm not sure it this helps.
I am using version 6.0.4.2 of LibreOffice on MacOS Mojave (version 10.14.6)
Post Reply