如何在 Enterprise Architect 中以编程方式导出模板列表?
How to programmatically export template list in Enterprise Architect?
我需要以编程方式导出 EA 项目中的模板列表。
目前我可以通过 SQL 便签本获得该列表:
SELECT DocName AS TemplateName, Author AS TemplateLocation
FROM t_document
WHERE DocType = 'SSDOCSTYLE'
但是,如果我 运行 在脚本中执行此查询,则它不起作用,因为它缺少 elementID。
有人知道我该怎么做吗?
您需要执行几个步骤
- 使用
Repository.SQLQuery()
执行您的查询
- 使用 xml 库解析生成的 xml 字符串
- 遍历 xml 文档中的节点以获得实际结果
- 将结果导出到文件
我的 github VBScript library 中的一些片段可以提供帮助:
使用这些函数,您将获得一个包含查询结果的二维数组。
function getArrayFromQuery(sqlQuery)
dim xmlResult
xmlResult = Repository.SQLQuery(sqlQuery)
getArrayFromQuery = convertQueryResultToArray(xmlResult)
end function
'converts the query results from Repository.SQLQuery from xml format to a two dimensional array of strings
Public Function convertQueryResultToArray(xmlQueryResult)
Dim arrayCreated
Dim i
i = 0
Dim j
j = 0
Dim result()
Dim xDoc
Set xDoc = CreateObject( "MSXML2.DOMDocument" )
'load the resultset in the xml document
If xDoc.LoadXML(xmlQueryResult) Then
'select the rows
Dim rowList
Set rowList = xDoc.SelectNodes("//Row")
Dim rowNode
Dim fieldNode
arrayCreated = False
'loop rows and find fields
For Each rowNode In rowList
j = 0
If (rowNode.HasChildNodes) Then
'redim array (only once)
If Not arrayCreated Then
ReDim result(rowList.Length, rowNode.ChildNodes.Length)
arrayCreated = True
End If
For Each fieldNode In rowNode.ChildNodes
'write f
result(i, j) = fieldNode.Text
j = j + 1
Next
End If
i = i + 1
Next
'make sure the array has a dimension even is we don't have any results
if not arrayCreated then
ReDim result(0, 0)
end if
end if
convertQueryResultToArray = result
End Function
我需要以编程方式导出 EA 项目中的模板列表。 目前我可以通过 SQL 便签本获得该列表:
SELECT DocName AS TemplateName, Author AS TemplateLocation FROM t_document WHERE DocType = 'SSDOCSTYLE'
但是,如果我 运行 在脚本中执行此查询,则它不起作用,因为它缺少 elementID。
有人知道我该怎么做吗?
您需要执行几个步骤
- 使用
Repository.SQLQuery()
执行您的查询
- 使用 xml 库解析生成的 xml 字符串
- 遍历 xml 文档中的节点以获得实际结果
- 将结果导出到文件
我的 github VBScript library 中的一些片段可以提供帮助:
使用这些函数,您将获得一个包含查询结果的二维数组。
function getArrayFromQuery(sqlQuery)
dim xmlResult
xmlResult = Repository.SQLQuery(sqlQuery)
getArrayFromQuery = convertQueryResultToArray(xmlResult)
end function
'converts the query results from Repository.SQLQuery from xml format to a two dimensional array of strings
Public Function convertQueryResultToArray(xmlQueryResult)
Dim arrayCreated
Dim i
i = 0
Dim j
j = 0
Dim result()
Dim xDoc
Set xDoc = CreateObject( "MSXML2.DOMDocument" )
'load the resultset in the xml document
If xDoc.LoadXML(xmlQueryResult) Then
'select the rows
Dim rowList
Set rowList = xDoc.SelectNodes("//Row")
Dim rowNode
Dim fieldNode
arrayCreated = False
'loop rows and find fields
For Each rowNode In rowList
j = 0
If (rowNode.HasChildNodes) Then
'redim array (only once)
If Not arrayCreated Then
ReDim result(rowList.Length, rowNode.ChildNodes.Length)
arrayCreated = True
End If
For Each fieldNode In rowNode.ChildNodes
'write f
result(i, j) = fieldNode.Text
j = j + 1
Next
End If
i = i + 1
Next
'make sure the array has a dimension even is we don't have any results
if not arrayCreated then
ReDim result(0, 0)
end if
end if
convertQueryResultToArray = result
End Function