i have a very strange problem which i cannot solve at the moment.
i try to parse a xml string with Regex.Matches to get all xml Nodes with a specific name.
it worked until now.
i have a xml input string with exactly 30 xml nodes named "row"
for some freaky reason my code returns me 26 nodes.. i have actually NO idea why there are 4 missing.
Heres my code to parse the data:
public static List<String> getXMLNodeContentFromSQLQueryString(String queryString, String rowName)
{
List<String> returnVal = new List<string>();
MatchCollection matchCollection = Regex.Matches(queryString, "<" + rowName + ">.*?</" + rowName + ">");
foreach (Match match in matchCollection)
{
String splitted = match.ToString();
splitted = splitted.Replace("<" + rowName + ">", "").Replace("</" + rowName + ">", "");
returnVal.Add(splitted);
}
if (returnVal.Count == 0)
returnVal.Add("");
return returnVal;
}
heres the xml string
"<?xml version=\"1.0\"?>\r\n<EADATA version=\"1.0\" exporter=\"Enterprise Architect\">\r\n\t<Dataset_0><Data><Row><OperationID>5</OperationID><Object_ID>135</Object_ID><Name>applyForward</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>1</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{84137450-8053-46eb-ACD5-574741233ABC}</ea_guid></Row><Row><OperationID>6</OperationID><Object_ID>135</Object_ID><Name>applyBackward</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>0</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{416E8BF3-9D6D-4fb3-8C32-05E4E6B8EDDD}</ea_guid></Row><Row><OperationID>12</OperationID><Object_ID>240</Object_ID><Name>copy</Name><Scope>Public</Scope><Type>EObject</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>0</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{E57518A9-9A91-4b0f-9311-F7AF3177F809}</ea_guid></Row><Row><OperationID>13</OperationID><Object_ID>240</Object_ID><Name>embedSDMInEAnnotation</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>1</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{44F4A863-86CB-4889-B179-3F4BA1F68D8D}</ea_guid></Row><Row><OperationID>18</OperationID><Object_ID>273</Object_ID><Name>configure</Name><Scope>Public</Scope><Type>EBoolean</Type><ReturnArray>0</ReturnArray><Concurrency>Sequential</Concurrency><Notes>0. Integrator creates GraphTriple and sets roots\r\n1. Adds the given graph triple to the translator\r\n2. Iterates over composite structure of input model and fills unprocessedNodes and unprocessedEdges (other collections are initially empty although this could be different in incremental mode)</Notes><Synchronized>0</Synchronized><Pos>0</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{B22FDBFE-C033-4ff5-81FB-2ED133A55F62}</ea_guid></Row><Row><OperationID>19</OperationID><Object_ID>273</Object_ID><Name>translate</Name><Scope>Public</Scope><Type>TranslationResult</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>1</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>136</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{2DFA0837-F09F-40f5-A4BD-CD3857D2D712}</ea_guid></Row><Row><OperationID>21</OperationID><Object_ID>165</Object_ID><Name>determineLNCC</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><Concurrency>Sequential</Concurrency><Notes>Iterate through all rules of the given TGG and consider edges in the following way:\r\nforall edges e in rule r\r\n-&gt; s(e) or t(e) are context elements\r\n-&gt; e is set to create\r\n=&gt; add quadruple containing the types of s(e), t(e), the name of e and the encoded equivalent if s, t or both are context elements.</Notes><Synchronized>0</Synchronized><Pos>0</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{0E021F1A-5CE7-4f68-B737-D2C11AA200ED}</ea_guid></Row><Row><OperationID>22</OperationID><Object_ID>273</Object_ID><Name>determineCandidateRulesForNode</Name><Scope>Public</Scope><Type>CandidateRules</Type><ReturnArray>0</ReturnArray><Concurrency>Sequential</Concurrency><Notes>1. Look up in table for operational rules that translate type(node).</Notes><Synchronized>0</Synchronized><Pos>2</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>352</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{7BE07512-219E-40f3-BB81-B1C5B5B15211}</ea_guid></Row><Row><OperationID>24</OperationID><Object_ID>135</Object_ID><Name>isAppropriate</Name><Scope>Public</Scope><Type>EOperation</Type><ReturnArray>0</ReturnArray><Concurrency>Sequential</Concurrency><Notes>1. check if core match exists in input graph starting from given entry node\r\n2. check if DEC is satisfied (call external method)\r\n3. process context on demand\r\n4. return the corresponding perform* EOperation or null if check failed.</Notes><Synchronized>0</Synchronized><Pos>2</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>183</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{EC74C95A-0D42-4b5d-98C6-0E3273664A8D}</ea_guid></Row><Row><OperationID>25</OperationID><Object_ID>273</Object_ID><Name>updateProcessedSets</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Notes>1. Determines the corresponding graph elements to the translated objects in the given ruleResult (also edges for translated references!!!)\r\n2. Adds these graph elements to the set of processed elements\r\n3. Be careful not to manipulate the set of unprocessed elements!</Notes><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>3</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{CE58DEC9-E683-4d49-8A92-986698AD7ABD}</ea_guid></Row><Row><OperationID>26</OperationID><Object_ID>165</Object_ID><Name>buildCandidateRulesLookupTable</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>1</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{BC2520AA-DB89-4280-ACE6-F6A8711EDC61}</ea_guid></Row><Row><OperationID>28</OperationID><Object_ID>273</Object_ID><Name>determineCandidateRulesForEdge</Name><Scope>Public</Scope><Type>CandidateRules</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>4</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>352</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{1070078F-FF2E-49ca-9432-2D50C026A0D6}</ea_guid></Row><Row><OperationID>29</OperationID><Object_ID>288</Object_ID><Name>eInvoke</Name><Scope>Public</Scope><Type>java.lang.Object</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>0</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{A1D00185-AE82-493e-AAAC-E916D2DD98D3}</ea_guid></Row><Row><OperationID>38</OperationID><Object_ID>240</Object_ID><Name>CREATE</Name><Scope>Public</Scope><Type>BindingOperator</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>4</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>115</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{42E99307-46D4-444b-886B-FBA399DF29F6}</ea_guid></Row><Row><OperationID>39</OperationID><Object_ID>240</Object_ID><Name>BACKWARD</Name><Scope>Public</Scope><Type>ApplicationTypes</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>5</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>272</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{D0F76449-7205-4f9c-A03D-C68F72A669C4}</ea_guid></Row><Row><OperationID>27</OperationID><Object_ID>165</Object_ID><Name>determineEntryNode</Name><Scope>Private</Scope><Type>TGGObjectVariable</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>2</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>128</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{12E442A3-491E-4dc2-9171-728084C3746F}</ea_guid></Row><Row><OperationID>30</OperationID><Object_ID>434</Object_ID><Name>invokeOperationWithSingleArg</Name><Scope>Public</Scope><Type>EObject</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>0</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>288</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{DDE51358-F82B-4100-A5D1-12154D533B41}</ea_guid></Row><Row><OperationID>31</OperationID><Object_ID>165</Object_ID><Name>deriveOperationalRules</Name><Scope>Public</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>3</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{30584C3D-773E-4256-BBE9-4FD226E45814}</ea_guid></Row><Row><OperationID>32</OperationID><Object_ID>165</Object_ID><Name>createOperationalRules</Name><Scope>Private</Scope><Type>void</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>4</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{ED7EF05C-D74B-4a0f-897D-DB7612AC5AEB}</ea_guid></Row><Row><OperationID>35</OperationID><Object_ID>240</Object_ID><Name>determineOperationSignature</Name><Scope>Public</Scope><Type>EString</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>2</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>0</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{999096A0-B224-4446-A8D5-CB581BA2DD20}</ea_guid></Row><Row><OperationID>36</OperationID><Object_ID>165</Object_ID><Name>createPerformOperation</Name><Scope>Private</Scope><Type>Activity</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>5</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>95</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{3414F021-9221-4be2-A133-28E6DAA25ADD}</ea_guid></Row><Row><OperationID>37</OperationID><Object_ID>240</Object_ID><Name>convertDirectionToAppropriateDomain</Name><Scope>Public</Scope><Type>DomainType</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>3</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>198</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{E83E8FA4-1802-4a2a-AF6B-81D5E4BAB83A}</ea_guid></Row><Row><OperationID>40</OperationID><Object_ID>240</Object_ID><Name>FORWARD</Name><Scope>Public</Scope><Type>ApplicationTypes</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>6</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>272</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{403AA3D8-A275-4763-BB64-8BDF6425EA18}</ea_guid></Row><Row><OperationID>42</OperationID><Object_ID>165</Object_ID><Name>createIsAppropriateOperation</Name><Scope>Public</Scope><Type>Activity</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>6</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>95</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{15A6B03B-DDE5-479d-A3DE-FA2A05970DE1}</ea_guid></Row><Row><OperationID>43</OperationID><Object_ID>240</Object_ID><Name>CHECK_ONLY</Name><Scope>Public</Scope><Type>BindingOperator</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>7</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>115</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{16268928-5197-4269-8A3D-5251DD8AA7A6}</ea_guid></Row><Row><OperationID>44</OperationID><Object_ID>240</Object_ID><Name>BOUND</Name><Scope>Public</Scope><Type>BindingState</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>8</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>113</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{5529869A-FE95-489e-BB61-BB1F46EBAB87}</ea_guid></Row><Row><OperationID>45</OperationID><Object_ID>240</Object_ID><Name>UNBOUND</Name><Scope>Public</Scope><Type>BindingState</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>9</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>113</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{A3CFAA93-BE84-4602-BAC7-AF42DE44F4AE}</ea_guid></Row><Row><OperationID>46</OperationID><Object_ID>240</Object_ID><Name>SUCCESS</Name><Scope>Public</Scope><Type>EdgeGuard</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>10</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>104</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{41D81F5E-E224-4171-A7B5-08BAD5D650E3}</ea_guid></Row><Row><OperationID>47</OperationID><Object_ID>240</Object_ID><Name>FAILURE</Name><Scope>Public</Scope><Type>EdgeGuard</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>11</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>104</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{8D2A6AF2-70C9-4d51-ADF2-CBD72BE0D8C1}</ea_guid></Row><Row><OperationID>48</OperationID><Object_ID>240</Object_ID><Name>MANDATORY</Name><Scope>Public</Scope><Type>BindingSemantics</Type><ReturnArray>0</ReturnArray><IsStatic>0</IsStatic><Concurrency>Sequential</Concurrency><Abstract>0</Abstract><Synchronized>0</Synchronized><Pos>12</Pos><Const>0</Const><Pure>FALSE</Pure><Classifier>114</Classifier><IsRoot>FALSE</IsRoot><IsLeaf>FALSE</IsLeaf><IsQuery>FALSE</IsQuery><ea_guid>{ADB4946B-AAA6-4ead-97DE-476DE4406DC1}</ea_guid></Row></Data></Dataset_0></EADATA>\r\n"
and ideas?
thanks
SOLVED!!!!!!!!!!!!!!!
Still have no idea where the problem was but solved the problem with using XMLReader thanks for you advices heres the code for interested people.
public static List getXMLNodeContentFromSQLQueryString(String queryString, String rowName) { List returnVal = new List();
// 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);
}
return returnVal;
}
Regexobject instance. Then you can useMatch m = re.Match(), andm.NextMatch()untilm.Success != true. That way you can look at each match individually and determine where it's missing.