ObjectCreateExpression ConvertXmlElementExpression(XmlElementExpression xmlElementExpression) { var newNode = new ObjectCreateExpression(new TypeReference("XElement"), xmlElementExpression.NameIsExpression ? new List <Expression> { xmlElementExpression.NameExpression } : Expressions(xmlElementExpression.XmlName)); foreach (XmlExpression attr in xmlElementExpression.Attributes) { if (attr is XmlAttributeExpression) { var a = attr as XmlAttributeExpression; newNode.Parameters.Add(new ObjectCreateExpression(new TypeReference("XAttribute"), new List <Expression> { new PrimitiveExpression(a.Name), a.IsLiteralValue ? new PrimitiveExpression(ConvertEntities(a.LiteralValue)) : a.ExpressionValue })); } else if (attr is XmlEmbeddedExpression) { newNode.Parameters.Add((attr as XmlEmbeddedExpression).InlineVBExpression); } } foreach (XmlExpression expr in xmlElementExpression.Children) { XmlContentExpression c = expr as XmlContentExpression; // skip whitespace text if (!(expr is XmlContentExpression && c.Type == XmlContentType.Text && string.IsNullOrWhiteSpace(c.Content))) { newNode.Parameters.Add(ConvertXmlExpression(expr)); } } return(newNode); }
public void VBNetSimpleCDataTest() { XmlContentExpression content = ParseUtil.ParseExpression <XmlContentExpression>("<![CDATA[<simple> <cdata>]]>"); Assert.AreEqual(XmlContentType.CData, content.Type); Assert.AreEqual("<simple> <cdata>", content.Content); Assert.AreEqual(new Location(1, 1), content.StartLocation); Assert.AreEqual(new Location(29, 1), content.EndLocation); }
public void VBNetSimplePreprocessingInstructionTest() { XmlContentExpression content = ParseUtil.ParseExpression <XmlContentExpression>("<?xml version='1.0'?>"); Assert.AreEqual(XmlContentType.ProcessingInstruction, content.Type); Assert.AreEqual("xml version='1.0'", content.Content); Assert.AreEqual(new Location(1, 1), content.StartLocation); Assert.AreEqual(new Location(22, 1), content.EndLocation); }
public void VBNetSimpleCommentTest() { XmlContentExpression content = ParseUtil.ParseExpression <XmlContentExpression>("<!-- test -->"); Assert.AreEqual(XmlContentType.Comment, content.Type); Assert.AreEqual(" test ", content.Content); Assert.AreEqual(new Location(1, 1), content.StartLocation); Assert.AreEqual(new Location(14, 1), content.EndLocation); }
void CheckContent(INode node, string content, XmlContentType type, Location start, Location end) { Assert.IsTrue(node is XmlContentExpression); XmlContentExpression expr = node as XmlContentExpression; Assert.AreEqual(type, expr.Type); Assert.AreEqual(content, expr.Content); Assert.AreEqual(start, expr.StartLocation); Assert.AreEqual(end, expr.EndLocation); }
Expression ConvertXmlContentExpression(XmlContentExpression xmlContentExpression) { Expression newNode = null; switch (xmlContentExpression.Type) { case XmlContentType.Comment: newNode = new ObjectCreateExpression(new TypeReference("XComment"), Expressions(xmlContentExpression.Content)); break; case XmlContentType.Text: newNode = new PrimitiveExpression(ConvertEntities(xmlContentExpression.Content)); break; case XmlContentType.CData: newNode = new ObjectCreateExpression(new TypeReference("XCData"), Expressions(xmlContentExpression.Content)); break; case XmlContentType.ProcessingInstruction: string content = xmlContentExpression.Content.Trim(); if (content.StartsWith("xml", StringComparison.OrdinalIgnoreCase)) { XDeclaration decl; try { decl = XDocument.Parse("<?" + content + "?><Dummy />").Declaration; } catch (XmlException) { decl = new XDeclaration(null, null, null); } newNode = new ObjectCreateExpression(new TypeReference("XDeclaration"), Expressions(decl.Version, decl.Encoding, decl.Standalone)); } else { string target = content.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? ""; string piData = content.IndexOf(' ') > -1 ? content.Substring(content.IndexOf(' ')) : ""; newNode = new ObjectCreateExpression(new TypeReference("XProcessingInstruction"), Expressions(target, piData)); } break; default: throw new Exception("Invalid value for XmlContentType"); } return(newNode); }
public override object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) { Expression newNode = ConvertXmlContentExpression(xmlContentExpression); if (newNode == null) { return(base.VisitXmlContentExpression(xmlContentExpression, data)); } ReplaceCurrentNode(newNode); if (newNode is ObjectCreateExpression) { return(base.VisitObjectCreateExpression((ObjectCreateExpression)newNode, data)); } else if (newNode is PrimitiveExpression) { return(base.VisitPrimitiveExpression((PrimitiveExpression)newNode, data)); } return(null); }
public override object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) { switch (xmlContentExpression.Type) { case XmlContentType.Comment: return(CreateResolveResult(new TypeReference("System.Xml.Linq.XComment"))); case XmlContentType.Text: return(CreateResolveResult(new TypeReference("System.Xml.Linq.XText"))); case XmlContentType.CData: return(CreateResolveResult(new TypeReference("System.Xml.Linq.XCData"))); case XmlContentType.ProcessingInstruction: if (xmlContentExpression.Content.StartsWith("xml ", StringComparison.OrdinalIgnoreCase)) { return(CreateResolveResult(new TypeReference("System.Xml.Linq.XDocumentType"))); } return(CreateResolveResult(new TypeReference("System.Xml.Linq.XProcessingInstruction"))); default: throw new Exception("Invalid value for XmlContentType"); } }
public virtual object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) { throw new global::System.NotImplementedException("XmlContentExpression"); }
public object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) { throw new NotImplementedException(); }