private ClassificationRulePackage ParseRule(XmlReader reader) { XDocument xdocument = XDocument.Load(reader); ClassificationRulePackage classificationRulePackage = new ClassificationRulePackage(); classificationRulePackage.RuleXml = xdocument.Root.ToString(SaveOptions.DisableFormatting); classificationRulePackage.VersionedDataClassificationIds = new HashSet <string>(from dataClassificationElement in xdocument.Descendants().AsParallel <XElement>() where ClassificationConstants.DataClassificationElementNames.Contains(dataClassificationElement.Name.LocalName) && ClassificationParser.IsVersionedDataClassification(dataClassificationElement) let dataClassificationId = dataClassificationElement.Attribute("id").Value.Trim() select dataClassificationId, StringComparer.OrdinalIgnoreCase); return(classificationRulePackage); }
public ClassificationRulePackage GetRulePackage(string ruleString) { ClassificationRulePackage result = null; XmlReader reader = null; try { XmlReaderSettings settings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Auto, IgnoreComments = true, DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }; using (StringReader stringReader = new StringReader(ruleString)) { using (XmlTextReader xmlTextReader = SafeXmlFactory.CreateSafeXmlTextReader(stringReader)) { XmlReader xmlReader; reader = (xmlReader = XmlReader.Create(xmlTextReader, settings)); try { result = this.ParseRule(reader); } finally { if (xmlReader != null) { ((IDisposable)xmlReader).Dispose(); } } } } } catch (XmlException e) { throw new ParserException(e); } catch (RulesValidationException e2) { throw new ParserException(e2, reader); } return(result); }