public Node Read(string xmlString) { Node node = null; if (xmlString.Contains("?xml")) { node = new XmlDeclarationNode {Name = "Declaration", Value = xmlString}; } else if (xmlString.Contains("<!--")) { node = new CommentNode {Name = "Comment", Value = xmlString.Substring(4, xmlString.Length - 7)}; }else if (xmlString.Contains("\\")) { node = new CommentNode {Name = "ScriptComment", Value = xmlString.Substring(2, xmlString.Length - 2)}; } else if (xmlString.Contains("<Item>")) { node = new TextNode {Name = "Text", Value = xmlString.Substring(6, xmlString.Length - 13)}; }else if (xmlString.ToLower().Contains("<script>")) { node = new TextNode {Name = "script", Value = xmlString.Substring(8, xmlString.Length - 17)}; } return node; }
protected XmlDeclarationNode MoveToDeclaration() { if (_attributeCount < 1) XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlDeclMissingVersion))); if (_attributeCount > 3) XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlMalformedDecl))); // version if (!CheckDeclAttribute(0, "version", "1.0", false, SR.XmlInvalidVersion)) XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlDeclMissingVersion))); // encoding/standalone // We only validate that they are the only attributes that exist. Encoding can have any value. if (_attributeCount > 1) { if (CheckDeclAttribute(1, "encoding", null, true, SR.XmlInvalidEncoding)) { if (_attributeCount == 3 && !CheckStandalone(2)) XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlMalformedDecl))); } else if (!CheckStandalone(1) || _attributeCount > 2) { XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.Format(SR.XmlMalformedDecl))); } } if (_declarationNode == null) { _declarationNode = new XmlDeclarationNode(_bufferReader); } MoveToNode(_declarationNode); return _declarationNode; }