public float GetFloatValue(IContentNode inode, float def) { XmlContentNode node = inode as XmlContentNode; if (node == null || node.Node == null) { throw new ContentException("Invalid content node"); } return(ParseFloat(node.Node.InnerText, def)); }
public IContentNode CreateNode(IContentNode inode, string name) { XmlContentNode rootNode = inode as XmlContentNode; if (rootNode == null || rootNode.Node == null) { throw new ContentException("Invalid content node"); } XmlElement node = rootNode.Node.OwnerDocument.CreateElement(name); rootNode.Node.AppendChild(node); return(new XmlContentNode(node)); }
public void SetAttribute <T>(IContentNode inode, string name, T value) { XmlContentNode node = inode as XmlContentNode; if (node == null || node.Node == null) { throw new ContentException("Invalid content node"); } XmlAttribute attribute = node.Node.OwnerDocument.CreateAttribute(name); attribute.Value = value.ToString(); node.Node.Attributes.Append(attribute); }
public float GetFloatAttribute(IContentNode inode, string attribute, float def) { XmlContentNode node = inode as XmlContentNode; if (node == null || node.Node == null) { throw new ContentException("Invalid content node"); } if (node.Node.Attributes != null && node.Node.Attributes.GetNamedItem(attribute) != null) { return(ParseFloat(node.Node.Attributes.GetNamedItem(attribute).Value, def)); } return(def); }
public string GetStringValue(IContentNode inode, string def) { XmlContentNode node = inode as XmlContentNode; if (node == null || node.Node == null) { throw new ContentException("Invalid content node"); } string text = node.Node.InnerText; string[] lines = text.Split('\n', '\r'); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Trim(' ', '\t', '\n', '\r'); } bool skipFirst = string.IsNullOrEmpty(lines[0]); bool skipLast = string.IsNullOrEmpty(lines[lines.Length - 1]); return(string.Join("\n", lines, skipFirst ? 1 : 0, lines.Length - (skipFirst ? 1 : 0) - (skipLast ? 1 : 0))); }
public int GetIntAttribute(IContentNode inode, string attribute, int def) { XmlContentNode node = inode as XmlContentNode; if (node == null || node.Node == null) { throw new ContentException("Invalid content node"); } if (node.Node.Attributes != null && node.Node.Attributes.GetNamedItem(attribute) != null) { int result; string value = node.Node.Attributes.GetNamedItem(attribute).Value; if (int.TryParse(value, out result)) { return(result); } else { Console.WriteLine("Invalid int attribute " + attribute + ", value " + value); } } return(def); }