Book a Demo

Author Topic: How should I add formatted="1" to XML for document fragments?  (Read 3598 times)

PeteC

  • EA User
  • **
  • Posts: 91
  • Karma: +1/-0
    • View Profile
I've created Jscript code to extract info, including Notes, for inclusion in a Document Template Fragment. It's all working, apart from notes including formatting codes as text.

The page https://sparxsystems.com/enterprise_architect_user_guide/15.2/model_publishing/example_output_of_an_rtf_templ.html states "If the text is a formatted Note, add formatted="1" to the field row".

What I can't figure out is how to included the formatted="1" into the field name. I'm using the ActiveXObject( "MSXML2.DOMDocument.6.0" ) to create my XML, following Sparx examples. If I try adding 'formatted="1"' to the name, I get a script error as the name cannot contain a space.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How should I add formatted="1" to XML for document fragments?
« Reply #1 on: April 26, 2021, 09:26:10 pm »
You should add it as an attribute of your node.

Here's an example of how to do that in VBScript

Code: [Select]
function MyRtfData (objectID, tagname)

dim xmlDOM
set  xmlDOM = CreateObject( "Microsoft.XMLDOM" )
'set  xmlDOM = CreateObject( "MSXML2.DOMDocument.4.0" )
xmlDOM.validateOnParse = false
xmlDOM.async = false

dim node
set node = xmlDOM.createProcessingInstruction( "xml", "version='1.0'")
    xmlDOM.appendChild node
'
dim xmlRoot
set xmlRoot = xmlDOM.createElement( "EADATA" )
xmlDOM.appendChild xmlRoot

dim xmlDataSet
set xmlDataSet = xmlDOM.createElement( "Dataset_0" )
xmlRoot.appendChild xmlDataSet

dim xmlData
set xmlData = xmlDOM.createElement( "Data" )
xmlDataSet.appendChild xmlData

dim xmlRow
set xmlRow = xmlDOM.createElement( "Row" )
xmlData.appendChild xmlRow

dim element as EA.Element
set element = Repository.GetElementByID(objectID)

dim formattedAttr
set formattedAttr = xmlDOM.createAttribute("formatted")
formattedAttr.nodeValue="1"

dim descriptionfull
descriptionfull = getTagContent(element.Notes, tagname)

dim xmlDescNL
set xmlDescNL = xmlDOM.createElement( "DescriptionNL" )

xmlDescNL.text = getTagContent(descriptionfull, "NL")
xmlDescNL.setAttributeNode(formattedAttr)
xmlRow.appendChild xmlDescNL

set formattedAttr = xmlDOM.createAttribute("formatted")
formattedAttr.nodeValue="1"

dim xmlDescFR
set xmlDescFR = xmlDOM.createElement( "DescriptionFR" )
xmlDescFR.text = getTagContent(descriptionfull, "FR")
xmlDescFR.setAttributeNode(formattedAttr)
xmlRow.appendChild xmlDescFR

MyRtfData = xmlDOM.xml
end function

Geert