Пример #1
0
 public static void JQuery(this HtmlDocument doc)
 {
     var script = doc.CreateElement("script");
     script.SetAttribute("text", Resources.Jquery);
     script.SetAttribute("type", "text/javascript");
     doc.GetElementsByTagName("head")[0].AppendChild(script);
 }
Пример #2
0
        public static XmlElement WithRoot(this XmlDocument document, string name)
        {
            XmlElement element = document.CreateElement(name);
            document.AppendChild(element);

            return element;
        }
Пример #3
0
 public static XmlElement CreateLineStyleElement(this XmlDocument doc, string lineWidthValue, string lineColorValue)
 {
     XmlElement lineStyleElement = doc.CreateElement("LineStyle");
     lineStyleElement.AppendChild(doc.CreateWidthElement(lineWidthValue));
     lineStyleElement.AppendChild(doc.CreateColorElement(lineColorValue));
     return lineStyleElement;
 }
Пример #4
0
 /// <summary>
 /// The <c>&lt;h1></c> to <c>&lt;h6></c> tags are used to define HTML headings. <remarks></remarks>
 /// <c>&lt;h1></c> defines the most important heading. <c>&lt;h6></c> defines the least important heading. <remarks> </remarks>
 ///  
 /// For more information see: <see cref="http://www.w3schools.com/tags/tag_hn.asp"/>
 /// </summary>
 /// <param name="builder">Builder for the Html Component</param>
 /// <param name="tier">The tier of the Heading element</param>
 /// <param name="text">The text value of the Heading element</param>
 /// <param name="attributes">Standard HTML Attributes (optional)</param>
 /// <returns></returns>
 public static IHtmlElement Heading(
     this IBuilder builder, 
     string text,
     HeadingTier tier,
     IHtmlAttributes attributes = null)
 {
     return builder.CreateElement(tier.ToString(), false, attributes).SetText(text);
 }
        public static XmlElement AppendElement(this XmlDocument doc, string name, string innerText = null)
        {
            XmlElement newElement = doc.CreateElement(name);
            newElement.InnerText = innerText;
            doc.AppendChild(newElement);

            return newElement;
        }
Пример #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <param name="nodeName"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        public static XmlElement CreateElementWithText(this XmlDocument xmlDoc, string nodeName, string val)
        {
            XmlElement el = xmlDoc.CreateElement(nodeName);
            XmlText txtXml = xmlDoc.CreateTextNode(val);
            el.AppendChild(txtXml);

            return el;
        }
Пример #7
0
        public static XmlElement AddElement(this XmlDocument document, string name)
        {
            var child = document.CreateElement(name);

            document.AppendChild(child);

            return child;
        }
Пример #8
0
 public static XmlElement CreatePlacemarkElement(this XmlDocument doc, string name, string styleUrl
     , string extrudeInfo, string modeInfo, string coordinatesInfo)
 {
     XmlElement placeMarkElement = doc.CreateElement("Placemark");
     placeMarkElement.AppendChild(doc.CreateNameElement(name));
     placeMarkElement.AppendChild(doc.CreateStyleUrlElement(styleUrl));
     placeMarkElement.AppendChild(doc.CreatePolygonElement(extrudeInfo, modeInfo, coordinatesInfo));
     return placeMarkElement;
 }
Пример #9
0
 public static XmlElement CreatePolygonElement(this XmlDocument doc, string extrudeInfo,
     string modeInfo, string coordinatesInfo)
 {
     XmlElement polygonElement = doc.CreateElement("Polygon");
     polygonElement.AppendChild(doc.CreateExtrudeElement(extrudeInfo));
     polygonElement.AppendChild(doc.CreateAltituteModeElement(modeInfo));
     polygonElement.AppendChild(doc.CreateOuterBoundaryIsElement(coordinatesInfo));
     return polygonElement;
 }
Пример #10
0
        /// <summary>
        /// Cria um novo elemento e retorna 
        /// </summary>
        /// <param name="doc">Documento ter como base para o novo elemento</param>
        /// <param name="name">Nome do novo elemento (tag)</param>
        /// <param name="value">Valor atribuído ao novo elemento.</param>
        /// <returns></returns>
        public static XmlElement CreateNFeElement(this XmlDocument doc, string name, object value)
        {
            XmlElement el = doc.CreateElement(name);

            if(value != null)
                el.InnerText = value.ToString();

            return el;
        }
Пример #11
0
		public static XmlElement AppendElement(this XmlDocument xmlDocument, string name, string value = null, XmlElement parent = null)
		{
			var element = xmlDocument.CreateElement(name);
			if (value != null) element.InnerText = value;
			if (parent == null)
				xmlDocument.AppendChild(element);
			else
				parent.AppendChild(element);
			return element;
		}
        public static void InsertAppSetting(this XmlDocument document, string key, string value)
        {
            var appSettings = document.DocumentElement.SelectSingleNode("appSettings");

            var node = document.CreateElement("add");
            node.SetAttribute("key", key);
            node.SetAttribute("value", value);
            node.SetAttribute("Transform", ConfigurationTransformer.TransformNamespace, "Insert");

            appSettings.AppendChild(node);
        }
        /// <summary>
        /// Adds an element to the document.
        /// </summary>
        /// <param name="xmlDocument">The XML document.</param>
        /// <param name="elementName">The XML element name.</param>
        /// <returns>The XML element.</returns>
        public static XmlElement AddElement(this XmlDocument xmlDocument, string elementName)
        {
            if (xmlDocument == null)
            {
                throw new ArgumentNullException("xmlDocument");
            }

            XmlElement xmlElement = xmlDocument.CreateElement(elementName);
            xmlDocument.AppendChild(xmlElement);
            return xmlElement;
        }
Пример #14
0
        private static void AddSheet(this XmlDocument dom, XmlNode head, string cssFilePath, string namespaceIfDesired)
        {
            //we're going to add file:// later
            cssFilePath = cssFilePath.Replace("file:///", "");
            cssFilePath = cssFilePath.Replace("file://", "");
            cssFilePath = "file://" + cssFilePath;

            var link = string.IsNullOrEmpty(namespaceIfDesired) ? dom.CreateElement("link") : dom.CreateElement("link", namespaceIfDesired);
            link.SetAttribute("rel", "stylesheet");

            if(cssFilePath.Contains(Path.DirectorySeparatorChar.ToString())) // review: not sure about relative vs. complete paths
            {
                link.SetAttribute("href", cssFilePath);
            }
            else //at least with gecko/firefox, something like "file://foo.css" is never found, so just give it raw
            {
                link.SetAttribute("href",cssFilePath);
            }
            link.SetAttribute("type", "text/css");
            head.AppendChild(link);
        }
Пример #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <param name="nodeName"></param>
        public static XmlElement AddRootNode(this XmlDocument xmlDoc, string nodeName)
        {
            //let's add the XML declaration section
            XmlNode xmlnode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
            xmlDoc.AppendChild(xmlnode);

            //let's add the root element
            XmlElement xmlElem = xmlDoc.CreateElement("", nodeName, "");
            xmlDoc.AppendChild(xmlElem);

            return xmlElem;
        }
        public static XmlNode CreateXPath(this XmlDocument doc, string xpath)
        {
            XmlNode node = doc;
            foreach (var part in xpath.Substring(1).Split('/'))
            {
                var nodes = node.SelectNodes(part);
                if (nodes.Count > 1)
                    throw new Exception("Xpath '" + xpath + "' was found multiple times!");

                if (nodes.Count == 1)
                {
                    node = nodes[0];
                    continue;
                }

                if (part.StartsWith("@"))
                {
                    var anode = doc.CreateAttribute(part.Substring(1));
                    node.Attributes.Append(anode);
                    node = anode;
                }
                else
                {
                    string elName, attrib = null;
                    if (part.Contains("["))
                    {
                        part.SplitOnce("[", out elName, out attrib);
                        if (!attrib.EndsWith("]")) throw new Exception("Unsupported XPath (missing ]): " + part);
                        attrib = attrib.Substring(0, attrib.Length - 1);
                    }
                    else elName = part;

                    XmlNode next = doc.CreateElement(elName);
                    node.AppendChild(next);
                    node = next;

                    if (attrib != null)
                    {
                        if (!attrib.StartsWith("@")) throw new Exception("Unsupported XPath attrib (missing @): " + part);
                        string name, value;
                        attrib.Substring(1).SplitOnce("='", out name, out value);
                        if (string.IsNullOrEmpty(value) || !value.EndsWith("'")) throw new Exception("Unsupported XPath attrib: " + part);
                        value = value.Substring(0, value.Length - 1);
                        var anode = doc.CreateAttribute(name);
                        anode.Value = value;
                        node.Attributes.Append(anode);
                    }
                }
            }
            return node;
        }
Пример #17
0
		private static void AddSheet(this XmlDocument dom, XmlNode head, string cssFilePath, string namespaceIfDesired)
		{
			// don't modify http paths
			if (!cssFilePath.StartsWith("http"))
			{
				// we're going to add file:// later
				cssFilePath = cssFilePath.Replace("file:///", "").Replace("file://", "");
				
				// absolute or relative path?
				if (File.Exists(cssFilePath))
				{
					// this is a local file, use absolute path
					var file = new FileInfo(cssFilePath);
					cssFilePath = new Uri(file.FullName).AbsoluteUri;
				}
			}

			var link = string.IsNullOrEmpty(namespaceIfDesired) ? dom.CreateElement("link") : dom.CreateElement("link", namespaceIfDesired);
			link.SetAttribute("rel", "stylesheet");
			link.SetAttribute("href", cssFilePath);
			link.SetAttribute("type", "text/css");

			head.AppendChild(link);
		}
        public static void InsertConnectionString(this XmlDocument document, string name, string connectionString, string providerName = null)
        {
            var appSettings = document.DocumentElement.SelectSingleNode("connectionStrings");

            var node = document.CreateElement("add");
            node.SetAttribute("name", name);
            node.SetAttribute("connectionString", connectionString);

            if (!string.IsNullOrWhiteSpace(providerName))
                node.SetAttribute("providerName", providerName);

            node.SetAttribute("Transform", ConfigurationTransformer.TransformNamespace, "Insert");

            appSettings.AppendChild(node);
        }
Пример #19
0
 public static XmlElement EL(this XmlDocument doc, string name, AttributeCollection attributes = null, string text = null)
 {
     if (doc == null) {
     throw new ArgumentNullException("doc");
       }
       var rv = doc.CreateElement(name);
       if (text != null) {
     rv.InnerText = text;
       }
       if (attributes != null) {
     foreach (var i in attributes) {
       rv.SetAttribute(i.Key, i.Value);
     }
       }
       return rv;
 }
Пример #20
0
 public static XmlElement CreateElement(this XmlDocument doc, string name, string[][] atts, XmlNode[] children)
 {
     XmlElement element = doc.CreateElement (name);
     if (atts != null) {
         for (int i = 0; i < atts.Length; i ++) {
             if (atts[i] == null) continue;
             if (atts[i].Length == 2)
                 element.SetAttribute (atts[i][0], atts[i][1]);
         }
     }
     if (children != null) {
         for (int i = 0; i < children.Length; i ++) {
             if (children[i] != null) {
                 element.AppendChild (children[i]);
             }
         }
     }
     return element;
 }
        public static XmlElement CreateNewNode(this XmlDocument xmldoc, string sNode, string sText, params string[] sAttributes)
        {
            var xmlelem = xmldoc.CreateElement("", sNode, "");
            var xmltext = xmldoc.CreateTextNode(sText);
            xmlelem.AppendChild(xmltext);

            for (int i = 0; i < sAttributes.Length; i++)
            {
            if (i % 2 == 0)
            {
                var xmlAttribute = xmldoc.CreateAttribute("", sAttributes[i], "");
                xmlelem.SetAttributeNode(xmlAttribute);

                if ((i + 1) < sAttributes.Length)
                {
                    xmlAttribute.Value = sAttributes[i + 1];
                }

            }

            }
            return xmlelem;
        }
Пример #22
0
 CreateVSElement(
     this System.Xml.XmlDocument document,
     string name,
     string value = null,
     string condition = null,
     System.Xml.XmlElement parentEl = null)
 {
     const string ns = "http://schemas.microsoft.com/developer/msbuild/2003";
     var el = document.CreateElement(name, ns);
     if (null != value)
     {
         el.InnerText = value;
     }
     if (null != condition)
     {
         el.SetAttribute("Condition", condition);
     }
     if (null != parentEl)
     {
         parentEl.AppendChild(el);
     }
     return el;
 }
Пример #23
0
        /// <summary>
        /// Sync the elements/collections of the given view.
        /// </summary>
        internal static void SyncElementsFrom(this View view, IEnumerable<IAbstractElementInfo> elements)
        {
            view.Elements
                .Where(e => !elements.Any(i => i.Id == e.DefinitionId))
                .ToArray()
                .ForEach(e => e.Delete());

            view.Elements
                .GroupBy(x => x.DefinitionId)
                .Where(x => elements.Any(
                    i => x.Key == i.Id &&
                    (i.Cardinality == Cardinality.OneToOne || i.Cardinality == Cardinality.ZeroToOne) &&
                    x.Count() > 1))
                .SelectMany(x => x.Skip(1))
                .ForEach(x => x.Delete());

            var singletonElements = elements
                .Where(i => i.AutoCreate &&
                    !view.Elements.Any(e => e.DefinitionId == i.Id))
                .ToArray();

            singletonElements.OfType<IElementInfo>().ForEach(x => view.CreateElement(e => e.DefinitionId = x.Id));
            singletonElements.OfType<ICollectionInfo>().ForEach(x => view.CreateCollection(e => e.DefinitionId = x.Id));
        }
Пример #24
0
 public static IHtmlElement Paragraph(this IBuilder builder, IHtmlAttributes attributes = null)
 {
     return builder.CreateElement("p", false, attributes);
 }
Пример #25
0
 /// <summary>
 /// The <c>&lt;aside></c> defines some content aside from the content it is placed in. <remarks></remarks>
 /// The aside content should be related to the surrounding content. <remarks> </remarks>
 ///  
 /// For more information see: <see cref="http://www.w3schools.com/tags/tag_aside.asp"/>
 /// </summary>
 /// <param name="builder">Builder for the Html Component</param>
 /// <param name="attributes">Standard HTML Attributes (optional)</param>
 /// <returns></returns>
 public static IHtmlElement Aside(this IBuilder builder, IHtmlAttributes attributes = null)
 {
     return builder.CreateElement("aside", false, attributes);
 }
Пример #26
0
 public static XmlElement CreatePolyStyleElement(this XmlDocument doc, string polyColorValue)
 {
     XmlElement polyStyleElement = doc.CreateElement("PolyStyle");
     polyStyleElement.AppendChild(doc.CreateColorElement(polyColorValue));
     return polyStyleElement;
 }
Пример #27
0
        /// <summary>
        /// Executa um bloco de código Javascript em um documento DOM
        /// </summary>
        /// <param name="instance">Documento DOM</param>
        /// <param name="javascriptCode">Block de código Javascript a ser interpretado e executado</param>
        public static void RunJavascript(this HtmlDocument instance, string javascriptCode)
        {
            HtmlElement scriptEl = instance.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
            element.text = javascriptCode;

            if (instance.Body != null)
            {
                instance.Body.AppendChild(scriptEl);
            }
            else
            {
                HtmlElement head = instance.GetElementsByTagName("head")[0];
                head.AppendChild(scriptEl);
            }
        }
Пример #28
0
 public static XmlElement CreateOuterBoundaryIsElement(this XmlDocument doc, string coordinatesInfo)
 {
     XmlElement outerBoundaryIsElement = doc.CreateElement("outerBoundaryIs");
     outerBoundaryIsElement.AppendChild(doc.CreateLinearRingElement(coordinatesInfo));
     return outerBoundaryIsElement;
 }
Пример #29
0
 public static XmlElement CreateGeneralElement(this XmlDocument doc, string elementName, string value)
 {
     XmlElement element = doc.CreateElement(elementName);
     element.InnerText = value;
     return element;
 }
Пример #30
0
 public static XmlElement CreateLinearRingElement(this XmlDocument doc, string coordinatesInfo)
 {
     XmlElement linearRingElement = doc.CreateElement("LinearRing");
     linearRingElement.AppendChild(doc.CreateCoordinatesElement(coordinatesInfo));
     return linearRingElement;
 }