当前位置: 首页>>代码示例>>C#>>正文


C# IHTMLElement.getAttribute方法代码示例

本文整理汇总了C#中IHTMLElement.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# IHTMLElement.getAttribute方法的具体用法?C# IHTMLElement.getAttribute怎么用?C# IHTMLElement.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHTMLElement的用法示例。


在下文中一共展示了IHTMLElement.getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAttribute

 public static string GetAttribute(IHTMLElement ele, string attributeName)
 {
     object attri_obj = ele.getAttribute(attributeName, 0);
     if (attri_obj != null)
     {
         string attri = attri_obj.ToString();
         if (attri != null && !(attri.Equals(string.Empty)))
             return attributeName + " : " + attri;
         else
             return string.Empty;
     }
     else
         return string.Empty;
 }
开发者ID:krishnakanthms,项目名称:recordanywhere,代码行数:14,代码来源:Finder.cs

示例2: AddAttributeToList

        private static void AddAttributeToList(string attributeName, IHTMLElement element, ArrayList resources)
        {
            // For this element, try to find the attribute containing a relative path
            string path = null;

            Object pathObject = element.getAttribute(attributeName, HTMLAttributeFlags.DoNotEscapePaths);
            if (pathObject != DBNull.Value)
            {
                path = (string)pathObject;
            }

            // If a valid path was discovered, add it to the list
            if (path != null)
            {
                ResourceUrlInfo info = new ResourceUrlInfo();
                info.ResourceUrl = path;
                info.ResourceType = element.tagName;
                info.InnerText = element.innerText;
                resources.Add(info);
            }
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:21,代码来源:HTMLDocumentHelper.cs

示例3: ResetPath

        private static void ResetPath(string attributeName, IHTMLElement element, string baseUrl)
        {
            // For this element, try to find the attribute containing a relative path
            string relativePath = null;

            Object pathObject = element.getAttribute(attributeName, HTMLAttributeFlags.DoNotEscapePaths);
            if (pathObject != DBNull.Value)
            {
                if (pathObject is String)
                    relativePath = (string)pathObject;
            }

            // If a relative path was discovered and its not an internal anchor, reset it
            if (relativePath != null && !relativePath.StartsWith("#", StringComparison.OrdinalIgnoreCase) && !UrlHelper.IsUrl(relativePath))
            {
                // Reset the value of the attribute to the escaped Path
                element.setAttribute(attributeName,
                UrlHelper.EscapeRelativeURL(baseUrl, relativePath),
                HTMLAttributeFlags.CaseInSensitive);
            }
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:21,代码来源:HTMLDocumentHelper.cs

示例4: ElementHasAttribute

 /// <summary>
 /// Check whether the passed HTML element contains the specified attribute
 /// </summary>
 /// <param name="element">element to check</param>
 /// <param name="attribute">name of attribute</param>
 /// <returns>true if the element has the attribute, else false</returns>
 public static bool ElementHasAttribute(IHTMLElement element, string attribute)
 {
     if (element != null)
     {
         object attrib = element.getAttribute(attribute, 0);
         return attrib != DBNull.Value;
     }
     else
     {
         return false;
     }
 }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:18,代码来源:HTMLDocumentHelper.cs

示例5: WriteStartTag

        private string WriteStartTag(IHTMLElement element, string style)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<");
            sb.Append(element.tagName);

            if (style != null && style != String.Empty)
            {
                sb.AppendFormat(" style=\"{0}\"", style);
            }

            IHTMLDOMNode node = (IHTMLDOMNode)element;
            IHTMLAttributeCollection attrs = node.attributes as IHTMLAttributeCollection;
            if (attrs != null)
            {
                foreach (IHTMLDOMAttribute attr in attrs)
                {
                    string attrName = attr.nodeName as string;
                    if (attr.specified)
                    {
                        //get the raw attribute value (so that IE doesn't try to expand out paths in the value).
                        string attrValue = element.getAttribute(attrName, 2) as string;
                        if (attrValue == null)
                        {
                            //IE won't return some attributes (like class) using IHTMLElement.getAttribute(),
                            //so if the value is null, try to get the value directly from the DOM Attribute.
                            //Note: we can't use the DOM value by default, because IE will rewrite the value
                            //to contain a fully-qualified path on some attribures (like src and href).
                            attrValue = attr.nodeValue as string;

                            if (attrValue == null)
                            {
                                string upperAttrName = attrName.ToUpperInvariant();
                                if (upperAttrName == "COLSPAN")
                                {
                                    //avoid bug with getting the attr value for column span elements
                                    attrValue = (element as IHTMLTableCell).colSpan.ToString(CultureInfo.InvariantCulture);
                                }
                                else if (upperAttrName == "STYLE")
                                {
                                    //the style attribute value cannot be extracted as a string, so grab its CSS text instead
                                    attrValue = element.style.cssText;
                                }
                            }
                        }

                        if (attrName != null && attrValue != null)
                        {
                            //write out this attribute.
                            sb.AppendFormat(" {0}=\"{1}\"", attrName, attrValue);
                        }
                    }
                }
            }
            sb.Append(">");
            string startTag = sb.ToString();
            return startTag;
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:58,代码来源:BlogEditingTemplateStrategy.cs

示例6: GetContainingAnchorElement

        /// <summary>
        /// Gets the parent link element (if any) for the passed element
        /// </summary>
        /// <param name="element">element</param>
        /// <returns>link element (or null if this element or one of its parents are not a link)</returns>
        public static IHTMLAnchorElement GetContainingAnchorElement(IHTMLElement element)
        {
            // search up the parent heirarchy
            while (element != null)
            {
                // if it is an anchor that has an HREF (exclude anchors with only NAME)
                // then stop searching
                if (element is IHTMLAnchorElement)
                {
                    if (element.getAttribute("href", 2) != null)
                        return element as IHTMLAnchorElement;
                }

                // search parent
                element = element.parentElement;
            }

            // didn't find an anchor
            return null;
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:25,代码来源:HTMLElementHelper.cs

示例7: UpdateImageSource

        internal static void UpdateImageSource(ImagePropertiesInfo imgProperties, IHTMLElement imgElement, IBlogPostImageEditingContext editorContext, ImageInsertHandler imageInsertHandler, ImageDecoratorInvocationSource invocationSource)
        {
            ISupportingFile oldImageFile = null;
            try
            {
                oldImageFile = editorContext.SupportingFileService.GetFileByUri(new Uri((string)imgElement.getAttribute("src", 2)));
            }
            catch (UriFormatException) { }
            if (oldImageFile != null) //then this is a known supporting image file
            {
                using (new WaitCursor())
                {
                    BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editorContext.ImageList, oldImageFile.FileUri);
                    if (imageData != null)
                    {
                        //Create a new ImageData object based on the image data attached to the current image src file.
                        BlogPostImageData newImageData = (BlogPostImageData)imageData.Clone();

                        //initialize some handlers for creating files based on the image's existing ISupportingFile objects
                        //This is necessary so that the new image files are recognized as being updates to an existing image
                        //which allows the updates to be re-uploaded back to the same location.
                        CreateImageFileHandler inlineFileCreator = new CreateImageFileHandler(editorContext.SupportingFileService,
                                                                                              newImageData.InlineImageFile != null ? newImageData.InlineImageFile.SupportingFile : null);
                        CreateImageFileHandler linkedFileCreator = new CreateImageFileHandler(editorContext.SupportingFileService,
                                                                                              newImageData.LinkedImageFile != null ? newImageData.LinkedImageFile.SupportingFile : null);

                        //re-write the image files on disk using the latest settings
                        imageInsertHandler.WriteImages(imgProperties, true, invocationSource, new CreateFileCallback(inlineFileCreator.CreateFileCallback), new CreateFileCallback(linkedFileCreator.CreateFileCallback), editorContext.EditorOptions);

                        //update the ImageData file references
                        Size imageSizeWithBorder = imgProperties.InlineImageSizeWithBorder;

                        //force a refresh of the image size values in the DOM by setting the new size attributes
                        imgElement.setAttribute("width", imageSizeWithBorder.Width, 0);
                        imgElement.setAttribute("height", imageSizeWithBorder.Height, 0);

                        newImageData.InlineImageFile.SupportingFile = inlineFileCreator.ImageSupportingFile;
                        newImageData.InlineImageFile.Height = imageSizeWithBorder.Height;
                        newImageData.InlineImageFile.Width = imageSizeWithBorder.Width;
                        if (imgProperties.LinkTarget == LinkTargetType.IMAGE)
                        {
                            newImageData.LinkedImageFile = new ImageFileData(linkedFileCreator.ImageSupportingFile, imgProperties.LinkTargetImageSize.Width, imgProperties.LinkTargetImageSize.Height, ImageFileRelationship.Linked);
                        }
                        else
                            newImageData.LinkedImageFile = null;

                        //assign the image decorators applied during WriteImages
                        //Note: this is a clone so the sidebar doesn't affect the decorator values for the newImageData image src file
                        newImageData.ImageDecoratorSettings = (BlogPostSettingsBag)imgProperties.ImageDecorators.SettingsBag.Clone();

                        //update the upload settings
                        newImageData.UploadInfo.ImageServiceId = imgProperties.UploadServiceId;

                        //save the new image data in the image list
                        editorContext.ImageList.AddImage(newImageData);
                    }
                    else
                        Debug.Fail("imageData could not be located");
                }
            }

            if (imgProperties.LinkTarget == LinkTargetType.NONE)
            {
                imgProperties.RemoveLinkTarget();
            }
        }
开发者ID:dbremner,项目名称:OpenLiveWriter,代码行数:66,代码来源:ImageEditingPropertyHandler.cs

示例8: SingleInnerText

 private static string SingleInnerText(IHTMLElement element)
 {
   if (String.Equals(element.tagName, "img", StringComparison.CurrentCultureIgnoreCase))
   {
     return element.getAttribute("alt") ?? "";
   }
   return (element.innerText ?? "").Trim();
 }
开发者ID:jonnyzzz,项目名称:utils,代码行数:8,代码来源:SkyScanner.cs

示例9: ActiveElementAttribute

        public string ActiveElementAttribute(IHTMLElement element, string AttributeName)
        {
            if (element == null)
            {
                return "";
            }

            string strValue = element.getAttribute(AttributeName, 0) as string;
            if (strValue == null)
            {
                strValue = "";
            }
            return strValue;
        }
开发者ID:pusp,项目名称:o2platform,代码行数:14,代码来源:WatinScript.cs

示例10: GenerateBlock

        public static string GenerateBlock(string className, string elementId, ISmartContent sContent, bool displayInline, string content, bool noFloat, IHTMLElement element)
        {
            if (string.IsNullOrEmpty(content))
                return "";

            // generate the html to insert
            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.AppendFormat("<div class=\"{0}\"", className);
            if (!string.IsNullOrEmpty(elementId))
                htmlBuilder.AppendFormat(" id=\"{0}\"", elementId);

            if (element != null)
            {
                // Persist the language direction of the smart content if it's explicitly set.
                string currentDirection = element.getAttribute("dir", 2) as string;
                if (!String.IsNullOrEmpty(currentDirection))
                {
                    htmlBuilder.AppendFormat(" dir=\"{0}\"", currentDirection);
                }
            }

            StringBuilder styleBuilder = new StringBuilder();

            if (sContent.Layout.Alignment == Alignment.None
               || sContent.Layout.Alignment == Alignment.Right
               || sContent.Layout.Alignment == Alignment.Left)
            {
                // If the smart content is none/right/left we just use float
                if (!noFloat || sContent.Layout.Alignment != Alignment.None)
                {
                    AppendStyle(noFloat ? "text-align" : "float",
                                sContent.Layout.Alignment.ToString().ToLower(CultureInfo.InvariantCulture),
                                styleBuilder);
                }
            }
            else if (element != null && sContent.Layout.Alignment == Alignment.Center)
            {
                // If the alignment is centered then it needs to make sure float is set to none
                AppendStyle("float", "none", styleBuilder);
                AppendStyle("display", "block", styleBuilder);
                AppendStyle("margin-left", "auto", styleBuilder);
                AppendStyle("margin-right", "auto", styleBuilder);
                AppendStyle("width", element.offsetWidth.ToString(CultureInfo.InvariantCulture), styleBuilder);
            }

            if (displayInline && sContent.Layout.Alignment != Alignment.Center)
                AppendStyle("display", "inline", styleBuilder);

            if (sContent.Layout.Alignment != Alignment.Center)
                AppendStyle("margin", "0px", styleBuilder);

            AppendStyle("padding", ToPaddingString(sContent.Layout), styleBuilder);

            if (styleBuilder.Length > 0)
                htmlBuilder.AppendFormat(" style=\"{0}\"", styleBuilder.ToString());

            htmlBuilder.AppendFormat(">{0}</div>", content);

            return htmlBuilder.ToString();
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:61,代码来源:SmartContentInsertionHelper.cs

示例11: IsElementMatchType

 public static bool IsElementMatchType(IHTMLElement ele, string typeName)
 {
     return ((ele.getAttribute("type", 0) != null) && ele.getAttribute("type", 0).ToString().ToLower().Trim().Equals(typeName));
 }
开发者ID:purplecow,项目名称:AutoBroswer,代码行数:4,代码来源:HtmlUtil.cs

示例12: IsElementMatch

 public static bool IsElementMatch(IHTMLElement ele, ElementTag tag, string itemName, string keyword = "")
 {
     itemName = itemName.Trim();
     if (tag == ElementTag.ID)
     {
         return (!string.IsNullOrEmpty(ele.id) && ele.id.Trim().Equals(itemName));
     }
     if (tag == ElementTag.name)
     {
         return ((ele.getAttribute("name", 0) != null) && ele.getAttribute("name", 0).ToString().Trim().Equals(itemName));
     }
     if (tag == ElementTag.outerText)
     {
         return (!string.IsNullOrEmpty(ele.outerText) && (ele.outerText.Trim().IndexOf(itemName) != -1));
     }
     if (tag == ElementTag.className)
     {
         return (!string.IsNullOrEmpty(ele.className) && ele.className.Trim().Equals(itemName));
     }
     if (tag == ElementTag.outerHTML)
     {
         return (!string.IsNullOrEmpty(ele.outerHTML) && ele.outerHTML.Trim().Equals(itemName));
     }
     if (tag == ElementTag.value)
     {
         return ((ele.getAttribute("value", 0) != null) && ele.getAttribute("value", 0).ToString().Trim().Equals(itemName));
     }
     if (tag == ElementTag.href)
     {
         return ((ele.getAttribute("href", 0) != null) && ele.getAttribute("href", 0).ToString().Trim().Equals(itemName));
     }
     if (tag != ElementTag.src)
     {
         return false;
     }
     if (ele.getAttribute("src", 0) == null)
     {
         return false;
     }
     return (ele.getAttribute("src", 0).ToString().Trim().Equals(itemName) || (!string.IsNullOrEmpty(keyword) && (ele.getAttribute("src", 0).ToString().Trim().IndexOf(keyword) != -1)));
 }
开发者ID:purplecow,项目名称:AutoBroswer,代码行数:41,代码来源:HtmlUtil.cs

示例13: IsSmartContent

        private static bool IsSmartContent(IHTMLElement element)
        {
            // search up the parent heirarchy
            while (element != null)
            {
                if (0 == String.Compare(element.tagName, "div", StringComparison.OrdinalIgnoreCase))
                {
                    string className = element.getAttribute("className", 0) as string;
                    if (className == "wlWriterSmartContent" || className == "wlWriterEditableSmartContent")
                        return true;
                }

                // search parent
                element = element.parentElement;
            }
            // not in smart content
            return false;
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:18,代码来源:BlogPostRegionLocatorStrategy.cs

示例14: printElementStart

        /// <summary>
        /// Utility for properly printing the start tag for an element.
        /// This utility takes care of including/suppresing attributes and namespaces properly.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="element"></param>
        private static void printElementStart(HtmlWriter writer, IHTMLElement element)
        {
            string tagName = element.tagName;

            // If there is no tag name, this is mostly an artificial tag reported by mshtml,
            // and not really present in the markup
            // (e.g HTMLTableCaptionClass)
            if (string.IsNullOrEmpty(tagName))
            {
                return;
            }

            //XHTML tags are all lowercase
            tagName = tagName.ToLower(CultureInfo.InvariantCulture);
            //this is a standard HTML tag, so just write it out.
            writer.WriteStartElement(tagName);

            IHTMLDOMNode node = element as IHTMLDOMNode;
            IHTMLAttributeCollection attrs = node.attributes as IHTMLAttributeCollection;
            if (attrs != null)
            {
                foreach (IHTMLDOMAttribute attr in attrs)
                {
                    string attrName = attr.nodeName as string;
                    if (attr.specified)
                    {

                        string attrNameLower = attrName.ToLower(CultureInfo.InvariantCulture);

                        //get the raw attribute value (so that IE doesn't try to expand out paths in the value).
                        string attrValue = element.getAttribute(attrName, 2) as string;
                        if (attrValue == null)
                        {
                            //IE won't return some attributes (like class) using IHTMLElement.getAttribute(),
                            //so if the value is null, try to get the value directly from the DOM Attribute.
                            //Note: we can't use the DOM value by default, because IE will rewrite the value
                            //to contain a fully-qualified path on some attribures (like src and href).
                            attrValue = attr.nodeValue as string;

                            if (attrValue == null)
                            {
                                if ((attrNameLower == "hspace" || attrNameLower == "vspace") && attr.nodeValue is int)
                                {
                                    attrValue = ((int)attr.nodeValue).ToString(CultureInfo.InvariantCulture);
                                }
                                else if (attrNameLower == "style")
                                {
                                    //Avoid bug: Images that are resized with the editor insert a STYLE attribute.
                                    //IE won't return the style attribute using the standard API, so we have to grab
                                    //it from the style object
                                    attrValue = element.style.cssText;
                                }
                                else if (attrNameLower == "colspan")
                                {
                                    attrValue = (element as IHTMLTableCell).colSpan.ToString(CultureInfo.InvariantCulture);
                                }
                                else if (attrNameLower == "rowspan")
                                {
                                    attrValue = (element as IHTMLTableCell).rowSpan.ToString(CultureInfo.InvariantCulture);
                                }
                                else if (attrNameLower == "align" && attr.nodeValue is int)
                                {
                                    // This is not documented anywhere. Just discovered the values empirically on IE7 (Vista).
                                    switch ((int)attr.nodeValue)
                                    {
                                        case 1:
                                            attrValue = "left";
                                            break;
                                        case 2:
                                            attrValue = "center";
                                            break;
                                        case 3:
                                            attrValue = "right";
                                            break;
                                        case 4:
                                            attrValue = "texttop";
                                            break;
                                        case 5:
                                            attrValue = "absmiddle";
                                            break;
                                        case 6:
                                            attrValue = "baseline";
                                            break;
                                        case 7:
                                            attrValue = "absbottom";
                                            break;
                                        case 8:
                                            attrValue = "bottom";
                                            break;
                                        case 9:
                                            attrValue = "middle";
                                            break;
                                        case 10:
                                            attrValue = "top";
//.........这里部分代码省略.........
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:101,代码来源:FormattedHtmlPrinter.cs

示例15: IsCenteringNode

 private bool IsCenteringNode(IHTMLElement element)
 {
     return GlobalEditorOptions.SupportsFeature(ContentEditorFeature.CenterImageWithParagraph) && element != null &&
         element is IHTMLParaElement && element.getAttribute("align", 2) as string == "center";
 }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:5,代码来源:HtmlAlignDecoratorSettings.cs


注:本文中的IHTMLElement.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。