Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: wikitect on September 22, 2012, 05:08:31 am
-
I have a SQL query that returns the following XML via the Repository Class:
<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
<Dataset_0><Data>
<Row><ConnectorID>3736</ConnectorID></Row>
<Row><ConnectorID>3737</ConnectorID></Row>
</Data></Dataset_0></EADATA>
What I want is to construct an array with the 2 connector IDs in it. Looking at the built in XML functions within the EA JScript library, if I execute
XMLGetNodeText( XMLdoc , nodePath )
where
nodePath = ="EADATA/Dataset_0/Data/Row/ConnectorID"
I get the first value - 3736. I therefore know the Xpath expression is correct.
If I execute
XMLGetNodeTextArray( XMLdoc, nodePath)
I get an array of zero length.
What am I doing wrong?
-
Check out this community resource i wrote: http://community.sparxsystems.com/resources/scripts/execute-sql-query-and-return-result-dictionary-rows.
It uses MSXML2 to parse the resultset.
Btw, the result is stored in a dictionary rather than an array and there's a reason for that: empty columns are not included in the XML.
Hope this helps,
Paulus
-
hi
i use this method to parse EA SQL Results.
it even can be used on sub result which arent valid xml
e.g
<Row>
<ConnectorID>3736</ConnectorID>
<ea_guid>xxxx-xxxx-xxx...</ea_guid>
</Row>
can be queried for connectorId or guid.
heres the method which returns a list with only one item (value = "")
if the desired entry is not found.
public static List<String> getXMLNodeContentFromSQLQueryString(String queryString, String rowName)
{
List<String> returnVal = new List<string>();
String editedString = "<?xml version=\"1.0\"?>\r\n<DUMMY>" + queryString + "</DUMMY>";
Char[] array = queryString.ToCharArray();
if (queryString != "")
{
if (array[1] != '?')
queryString = editedString;
// load contents of file
TextReader textReader = new StringReader(queryString);
// process file contents
XmlDocument domDoc = new XmlDocument();
domDoc.Load(textReader);
XmlNodeList nodeList = domDoc.GetElementsByTagName(rowName);
foreach (XmlNode node in nodeList)
{
returnVal.Add(node.InnerXml);
}
}
if (returnVal.Count == 0)
returnVal.Add("");
return returnVal;
}