private void ProcessSymanticEntry(MicroDataEntry semanticEntry, CQ body) { if (semanticEntry.Type == MicroDataType.itemprop || semanticEntry.Type == MicroDataType.rel) { body.Select(semanticEntry.Selector).Attr(semanticEntry.Type.ToString(), semanticEntry.Value); } else if (semanticEntry.Type == MicroDataType.itemscope) { body.Select(semanticEntry.Selector).Each(node => node.SetAttribute("itemscope")); body.Select(semanticEntry.Selector).Attr("itemtype", semanticEntry.Value); } else { body.Select(semanticEntry.Selector).Attr(semanticEntry.Value, semanticEntry.Value); } }
public static IEnumerable<MicroDataEntry> Deserialize(string data) { List<MicroDataEntry> results = new List<MicroDataEntry>(); using (StringReader rd = new StringReader(data)) { using (XmlReader nodereader = XmlReader.Create(rd)) { nodereader.MoveToContent(); while (!nodereader.EOF) { if (nodereader.Name == "entry") { try { MicroDataEntry entry = new MicroDataEntry(); XElement el = XNode.ReadFrom(nodereader) as XElement; if (el != null) { IEnumerable<XAttribute> attr = el.Attributes(); foreach (XAttribute xAttribute in attr) { if (!string.IsNullOrWhiteSpace(xAttribute.Value)) { switch (xAttribute.Name.LocalName) { case "contentType": { Guid contentType; Guid.TryParse(xAttribute.Value, out contentType); entry.ContentType = contentType; } break; case "entryType": entry.Type = (MicroDataType) Enum.Parse(typeof (MicroDataType), xAttribute.Value); break; case "value": entry.Value = xAttribute.Value; break; case "selector": entry.Selector = xAttribute.Value; break; } } } results.Add(entry); } } // ReSharper disable once EmptyGeneralCatchClause catch { } } else { nodereader.Read(); } } } } return results.OrderBy(o => o.ContentType).ThenByDescending(o => o.Selector); }
public static IEnumerable <MicroDataEntry> Deserialize(string data) { List <MicroDataEntry> results = new List <MicroDataEntry>(); using (StringReader rd = new StringReader(data)) { using (XmlReader nodereader = XmlReader.Create(rd)) { nodereader.MoveToContent(); while (!nodereader.EOF) { if (nodereader.Name == "entry") { try { MicroDataEntry entry = new MicroDataEntry(); XElement el = XNode.ReadFrom(nodereader) as XElement; if (el != null) { IEnumerable <XAttribute> attr = el.Attributes(); foreach (XAttribute xAttribute in attr) { if (!string.IsNullOrWhiteSpace(xAttribute.Value)) { switch (xAttribute.Name.LocalName) { case "contentType": { Guid contentType; Guid.TryParse(xAttribute.Value, out contentType); entry.ContentType = contentType; } break; case "entryType": entry.Type = (MicroDataType)Enum.Parse(typeof(MicroDataType), xAttribute.Value); break; case "value": entry.Value = xAttribute.Value; break; case "selector": entry.Selector = xAttribute.Value; break; } } } results.Add(entry); } } // ReSharper disable once EmptyGeneralCatchClause catch { } } else { nodereader.Read(); } } } } return(results.OrderBy(o => o.ContentType).ThenByDescending(o => o.Selector)); }