如何解决如何在Enterprise Architect中以编程方式导出模板列表?
我需要以编程方式导出EA项目中的模板列表。 目前,我可以使用sql暂存器获取该列表:
选择DocName AS模板名称,作者AS模板位置 来自t_document 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。