Home Forums General XMetaL Discussion Resolve entity reference by code Reply To: Resolve entity reference by code

Derek Read

Reply to: Resolve entity reference by code

When you say you want to “resolve” the entity, what exactly do you mean? Does this mean you want to extract the value defined for the entity? I'm assuming we're talking about text entities. What do you need to do with the value?

If DOM supported it I think you would use nodeValue. The following shows some code that will not work (and I have nothing better to offer at the moment).

//XMetaL Script Language JScript:
var entList = ActiveDocument.doctype.entities;
//How many entities are defined?
//If we have at least one then display info for the first...
if(entList.length > 0) {
Application.Alert(entList.item(0).nodeType);  //<--this should be 6
Application.Alert(entList.item(0).nodeValue); //<--this should return null

That returns null for nodeValue because DOM (the spec) didn't define that for nodes of type entity (type 6) and XMetaL has not added an extension to the DOM to do that either.

[quote=XMetaL Developer Programmers Guide for 'nodeValue']The DOM specification details which types of nodes have values, and where the values come from:

DOMAttr: the attribute value
DOMText: the text
DOMCDATASection: content of the section
DOMProcessingInstruction: everything in the PI except the target.
DOMComment: content of the comment.
DOMCharacterReference: the decimal number corresponding to the character (extension to DOM)
All other nodes: null.
Set applies only to nodes whose value is not null by definition.

[quote=XMetaL Developer Programmers Guide for 'nodeType']The allowed values are specified by the DOM specification:

1: DOMElement
2: DOMAttr
3: DOMText
4: DOMCDATASection
5: DOMEntityReference
6: DOMEntity
7: DOMProcessingInstruction
8: DOMComment
9: Document (DOMDocument)
10: DOMDocumentType
11: DOMDocumentFragment
12: DOMNotation
505: DOMCharacterReference (extension to DOM)

Perhaps knowing what your ultimate goal is will allow me to look at alternative options.