public void Parse() { System.IO.StreamReader sr = new System.IO.StreamReader(GetFullPath()); XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Parse; XmlReader reader = XmlReader.Create(sr, settings); try { node = new NodeEntity(); node.SetNodeName(fileName); node.SetNodeID(0); node.SetDepth(0); node.Comment(false); while (reader.Read()) { ParseElement(reader); ParseText(reader); ParseCDATA(reader); ParseEndElement(reader); ParseComment(reader); } } catch (Exception) { throw; } finally { if (reader != null) { reader.Close(); } if (sr != null) { sr.Close(); } } }
private void ParseElement(XmlReader reader) { if (reader.NodeType != XmlNodeType.Element) { return; } string nodeName = reader.Name; NodeEntity newNode = new NodeEntity(); newNode.SetNodeName(nodeName); newNode.SetNodeID(currentNodeId); currentNodeId++; ParseAttributes(reader, newNode); if (currentNodeId == 1) { node = newNode; } else { node.FindTail(depth).AddChild(newNode); } if (!reader.IsEmptyElement) { depth++; } }
public void Refresh() { NodeEntity r = Root(); newDepth = 0; newNodeId = 0; r.SetDepth(newDepth); r.SetNodeID(newNodeId); Refresh(r); }
public NodeEntity CloneWithoutChildren() { NodeEntity ret = new NodeEntity(); attrList.ForEach(v => { ret.AddAttr(v.Clone()); }); ret.SetNodeName(nodeName); ret.SetNodeID(nodeId); ret.SetDepth(depth); ret.SetNodeValue(nodeValue); ret.Comment(isComment); return(ret); }
protected void ParseComment(XmlReader reader) { if (reader.NodeType != XmlNodeType.Comment) { return; } NodeEntity newNode = new NodeEntity(); newNode.SetNodeName(@"Comment"); newNode.SetNodeID(currentNodeId); newNode.SetDepth(depth); newNode.SetNodeValue(reader.Value.Trim()); newNode.Comment(true); currentNodeId++; node.FindTail(depth).AddChild(newNode); }
protected void ParseElement(XmlReader reader) { if (reader.NodeType != XmlNodeType.Element) { return; } string nodeName = reader.Name; NodeEntity newNode = new NodeEntity(); newNode.SetNodeName(nodeName); newNode.SetNodeID(currentNodeId); newNode.SetDepth(depth); newNode.Comment(false); currentNodeId++; node.FindTail(depth).AddChild(newNode); ParseAttributes(reader, newNode); if (!reader.IsEmptyElement) { depth++; } }