public List <LabelEditorItem> GetNames(out int maxId) { // <cml:name dictRef="nameDict:generic">ester</cml:name> // Initialise output parameters maxId = 0; List <XmlNode> list = GetNames(); List <LabelEditorItem> items = new List <LabelEditorItem>(); foreach (XmlNode node in list) { LabelEditorItem editorItem = new LabelEditorItem(); string id = GetAttributeValue(node, Id); if (!string.IsNullOrEmpty(id)) { editorItem.Id = id; int n; if (int.TryParse(id.Substring(1), out n)) { maxId = Math.Max(maxId, n); } } string dictRefValue = GetAttributeValue(node, DictRef); editorItem.Attribute = dictRefValue; editorItem.Value = node.InnerText; items.Add(editorItem); } foreach (LabelEditorItem item in items) { if (string.IsNullOrEmpty(item.Id)) { maxId++; item.Id = "n" + maxId; } } return(items); }
public List <LabelEditorItem> GetFormulae(out int maxId, out string conciseFormula) { // Variations of formula we need to cope with ... // <formula concise="C 5 H 10 O 2"/> // <cml:formula inline="AcOMe" concise="C 2 H 6 O 2" /> // <formula convention="pubchem:formula" inline="C4H9NO2" concise="C 4 H 9 N 1 O 2" /> // <formula convention="pubchem:CanonicalSmiles" inline="C(CC(=O)O)CN" concise="C 4 H 9 N 1 O 2" /> // <formula convention="pubchem:IsomericSmiles" inline="C(CC(=O)O)CN" concise="C 4 H 9 N 1 O 2" /> // Initialise output parameters maxId = 0; conciseFormula = ""; List <XmlNode> list = GetFormulae(); List <LabelEditorItem> items = new List <LabelEditorItem>(); foreach (XmlNode node in list) { string concise = GetAttributeValue(node, Concise); // Only grab 1st concise formula if (string.IsNullOrEmpty(conciseFormula) && !string.IsNullOrEmpty(concise)) { conciseFormula = concise; } // Count attributes which are not concise formula and are not empty int count = 0; foreach (XmlAttribute attribute in node.Attributes) { if (!attribute.Name.Equals(Concise) && !string.IsNullOrEmpty(attribute.Value)) { count++; } } if (count > 0) { LabelEditorItem editorItem = new LabelEditorItem(); string id = GetAttributeValue(node, Id); if (!string.IsNullOrEmpty(id)) { editorItem.Id = id; int n; if (int.TryParse(id.Substring(1), out n)) { maxId = Math.Max(maxId, n); } } string inline = GetAttributeValue(node, Inline); if (!string.IsNullOrEmpty(inline)) { editorItem.Value = inline; } string convention = GetAttributeValue(node, Convention); if (!string.IsNullOrEmpty(convention)) { editorItem.Attribute = convention; } items.Add(editorItem); } } foreach (LabelEditorItem item in items) { if (string.IsNullOrEmpty(item.Id)) { maxId++; item.Id = "f" + maxId; } } return(items); }