private void ProcessLine(string line) { if (line.Length == 0 || line[0] == '#') { return; //comment line } int e = line.IndexOf('='); if (e != -1 && _current != null) { string name0 = CutPrecedingSpace(line.Substring(0, e)); string value = e == line.Length - 1? "" : CutPrecedingSpace(line.Substring(e + 1)); _current.Set(name0, value); } else if (line[line.Length - 1] == '{') { string name = line.Substring(0, line.IndexOf(' ')); _current = _current == null? new StructuredText(null, name) : _current.AddChild(name); if (_root == null) { _root = _current; //最初のNodeをルートとする } } else if (line[line.Length - 1] == '}') { _current = _current.Parent; } }
private StructuredText Read(XmlElement elem) { StructuredText node = new StructuredText(elem.LocalName); foreach (XmlAttribute attr in elem.Attributes) node.Set(attr.LocalName, attr.Value); foreach (XmlNode ch in elem.ChildNodes) { XmlElement ce = ch as XmlElement; if (ce != null) node.AddChild(Read(ce)); } return node; }
public void Test2_Nodes1() { StructuredText r = CreateRoot(); StructuredText c1 = r.GetOrCreateChild("C"); Assert.AreEqual("C", c1.Name); Assert.AreSame(r, c1.Parent); StructuredText c2 = r.AddChild("C"); Assert.AreSame(r, c2.Parent); Assert.AreSame(c1, r.FindChild("C")); //must be the first child IList il = r.FindMultipleNote("C"); Assert.AreEqual(2, il.Count); Assert.AreSame(c2, il[1]); }
private StructuredText Read(XmlElement elem) { StructuredText node = new StructuredText(elem.LocalName); foreach (XmlAttribute attr in elem.Attributes) { node.Set(attr.LocalName, attr.Value); } foreach (XmlNode ch in elem.ChildNodes) { XmlElement ce = ch as XmlElement; if (ce != null) { node.AddChild(Read(ce)); } } return(node); }