static void RemoveXmlBase(XmlElement element) { element.RemoveAttribute ("xml:base"); if (!element.HasChildNodes) { return; } IEnumerable<XmlElement> children = element.ChildNodes.OfType<XmlElement> (); foreach (XmlElement child in children) { RemoveXmlBase (child); } }
public static void SetAttribute(XmlElement Element, string Name, object Value, string DefaultValue) { if (Value == null || string.Compare(Value.ToString(), DefaultValue) == 0) { Element.RemoveAttribute(Name); } else { Element.SetAttribute(Name, Value.ToString()); } }
public void core0011A() { string computedValue = "";//""; string expectedValue = "False"; System.Xml.XmlAttribute streetAttr = null; System.Xml.XmlElement testNode = null; testResults results = new testResults("Core0011A"); try { results.description = "Re-setting an attribute to its default value " + "requires that the attribute be deleted. The " + "implementation should create a new attribute " + "with its \"specified\" attribute set to false."; // // Retrieve the targeted data, remove the "street" attribute and capture // its specified attribute. // testNode = (System.Xml.XmlElement)util.nodeObject(util.THIRD, util.SIXTH); testNode.RemoveAttribute("street");//testNode.node.removeAttribute("street"); streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street"); computedValue = streetAttr.Specified.ToString(); } catch (System.Exception ex) { computedValue = "Exception " + ex.Message; } // // Write out results // results.expected = expectedValue; results.actual = computedValue; Assert.AreEqual(results.expected, results.actual); // return results; }
public static XmlElement CrossDomainLink(this HtmlElementContext context, XmlElement element) { string domain = context.Parameters.GetValue<string>("link-domain", String.Empty); string redirect = context.Parameters.GetValue<string>("link-redirect"); string location = element.GetAttribute("href"); element.RemoveAttribute("target"); Uri uri; if (!Uri.TryCreate(location, UriKind.Absolute, out uri)) if (!Uri.TryCreate("http://" + location, UriKind.Absolute, out uri)) return null; if ((uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) && !uri.Host.EndsWith(domain, StringComparison.OrdinalIgnoreCase)) { if (!String.IsNullOrEmpty(redirect)) element.SetAttribute("href", String.Format("{0}?url={1}", redirect, Uri.EscapeDataString(uri.AbsoluteUri))); element.SetAttribute("target", "_blank"); element.SetAttribute("rel", "nofollow"); } return element; }
internal void PostProcessElement(ITemplateParsingState templateParsingState, IDictionary<string, object> getParameters, XmlElement element) { if (templateParsingState.TemplateHandlerLocator.TemplatingConstants.HtmlNamespaces.Contains(element.NamespaceURI)) if (element.LocalName == "script") { // Don't allow empty <script /> tags if (null == element.InnerText) element.InnerText = ""; if (element.InnerText.Length > 0) if (!templateParsingState.WebConnection.CookiesFromBrowser.ContainsKey(templateParsingState.TemplateHandlerLocator.TemplatingConstants.JavascriptDebugModeCookie)) try { IEnumerable<XmlNode> toIterate = Enumerable<XmlNode>.FastCopy(Enumerable<XmlNode>.Cast(element.ChildNodes)); // The xml contents of a script tag are minified in case xml is quoted StringBuilder scriptBuilder = new StringBuilder((element.InnerXml.Length * 5) / 4); foreach (XmlNode node in toIterate) if (node is XmlText) scriptBuilder.Append(node.InnerText); else scriptBuilder.Append(node.OuterXml); string minified = JavaScriptMinifier.Instance.Minify(scriptBuilder.ToString()); foreach (XmlNode node in toIterate) element.RemoveChild(node); element.AppendChild( templateParsingState.TemplateDocument.CreateTextNode(minified)); } catch (Exception e) { log.Warn("Exception minimizing Javascript:\n" + element.InnerXml, e); } } else if (element.LocalName == "link") { string typeString = element.GetAttribute("type"); if (typeString == "text/css" || typeString == "image/x-icon") AddBrowserCache(templateParsingState, element.Attributes["href"]); } else if (element.LocalName == "img") AddBrowserCache(templateParsingState, element.Attributes["src"]); else if (element.LocalName == "embed") AddBrowserCache(templateParsingState, element.Attributes["src"]); else { string browserCacheAttributeName = element.GetAttribute( "browsercacheattribute", templateParsingState.TemplateHandlerLocator.TemplatingConstants.TemplateNamespace); if (browserCacheAttributeName != null) if (browserCacheAttributeName.Length > 0) { AddBrowserCache(templateParsingState, element.Attributes[browserCacheAttributeName]); element.RemoveAttribute( "browsercacheattribute", templateParsingState.TemplateHandlerLocator.TemplatingConstants.TemplateNamespace); } } }
public void setSettingRowDefault(ListBoxItem lbiRow, Dictionary<ListBoxItem, XmlElement> mapLbiRow, ref XmlElement xeDef) { XmlElement xe; if (mapLbiRow.TryGetValue(lbiRow, out xe) && xe != null) { if (xeDef != null) { xeDef.RemoveAttribute("isDefault"); } xe.SetAttribute("isDefault", "true"); xeDef = xe; refreshSetting("ThemeSetting", mx_lbTheme, m_mapLbiThemeRow, new string[0], ref m_xeThemeDef); } }
/// <summary> /// Inspects a Category element. /// </summary> /// <param name="element">The Category element to inspect.</param> private void InspectCategoryElement(XmlElement element) { if (element.HasAttribute("AppData")) { if (String.Empty == element.GetAttribute("AppData")) { this.OnError(InspectorTestType.CategoryAppDataEmpty, element, "The Category/@AppData attribute's value cannot be an empty string. If you want the value to be null or empty, simply remove the entire attribute."); element.RemoveAttribute("AppData"); } } }
void SaveCoreProperty(XmlElement elem, string val, string attr, string prop) { if (properties != null && properties.HasProperty (prop)) { elem.RemoveAttribute (attr); if (!string.IsNullOrEmpty (val)) properties.SetPropertyValue (prop, val); else properties.RemoveProperty (prop); } else if (string.IsNullOrEmpty (val)) elem.RemoveAttribute (attr); else elem.SetAttribute (attr, val); }
/// <summary> /// Persists this mapping filter to the specified XmlElement /// </summary> /// <param name="filter">The filter to save</param> /// <param name="element"></param> internal static void Save(MappingsFilter filter, XmlElement element) { if (filter != null && filter.HasVersionFilter) { element.SetAttribute("sifVersion", filter.SifVersion); } else { element.RemoveAttribute("sifVersion"); } if (filter != null && filter.HasDirectionFilter) { element.SetAttribute("direction", filter.Direction.ToString("G")); switch (filter.Direction) { case MappingDirection.Inbound: element.SetAttribute("direction", "inbound"); break; case MappingDirection.Outbound: element.SetAttribute("direction", "outbound"); break; } } else { element.RemoveAttribute("direction"); } }
private Uri GetLocalPathUri(XmlElement cacheElm) { if (cacheElm.HasAttribute("local-path")) { string path = Path.Combine(cacheDir, cacheElm.GetAttribute("local-path")); if(File.Exists(path)) { path = "file:///" + path.Replace('\\', '/'); return new Uri(path); } else { cacheElm.RemoveAttribute("local-path"); return null; } } else { return null; } }
public static void UpdateImgMetdataAttributesToMatchImage(string folderPath, XmlElement imgElement, IProgress progress, Metadata metadata) { //see also PageEditingModel.UpdateMetadataAttributesOnImage(), which does the same thing but on the browser dom var fileName = imgElement.GetOptionalStringAttribute("src", string.Empty).ToLower(); var end = fileName.IndexOf('?'); if (end > 0) { fileName = fileName.Substring(0, end); } if (fileName == "placeholder.png" || fileName == "license.png") return; if (string.IsNullOrEmpty(fileName)) { Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Warning: img has no or empty src attribute"); //Debug.Fail(" (Debug only) img has no or empty src attribute"); return; // they have bigger problems, which aren't appropriate to deal with here. } if (metadata == null) { progress.WriteStatus("Reading metadata from " + fileName); var path = folderPath.CombineForPath(fileName); if (!File.Exists(path)) // they have bigger problems, which aren't appropriate to deal with here. { imgElement.RemoveAttribute("data-copyright"); imgElement.RemoveAttribute("data-creator"); imgElement.RemoveAttribute("data-license"); Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Image " + path + " is missing"); Debug.Fail(" (Debug only) Image " + path + " is missing"); return; } using (var image = PalasoImage.FromFile(path)) { metadata = image.Metadata; } } progress.WriteStatus("Writing metadata to HTML for " + fileName); imgElement.SetAttribute("data-copyright", String.IsNullOrEmpty(metadata.CopyrightNotice) ? "" : metadata.CopyrightNotice); imgElement.SetAttribute("data-creator", String.IsNullOrEmpty(metadata.Creator) ? "" : metadata.Creator); imgElement.SetAttribute("data-license", metadata.License == null ? "" : metadata.License.ToString()); }
static void SetOrRemoveAttribute(XmlElement element, string name, string value){ if (value == null || value == string.Empty){ if (element.HasAttribute(name)) element.RemoveAttribute(name); }else{ if (element.GetAttribute(name) != value) element.SetAttribute(name, value); } }
public static void UpdateImgMetdataAttributesToMatchImage(string folderPath, XmlElement imgElement, IProgress progress, Metadata metadata) { //see also PageEditingModel.UpdateMetadataAttributesOnImage(), which does the same thing but on the browser dom var url = HtmlDom.GetImageElementUrl(new ElementProxy(imgElement)); var end = url.NotEncoded.IndexOf('?'); string fileName = url.NotEncoded; if (end > 0) { fileName = fileName.Substring(0, end); } if (fileName.ToLowerInvariant() == "placeholder.png" || fileName.ToLowerInvariant() == "license.png") return; if (string.IsNullOrEmpty(fileName)) { Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Warning: img has no or empty src attribute"); //Debug.Fail(" (Debug only) img has no or empty src attribute"); return; // they have bigger problems, which aren't appropriate to deal with here. } if (metadata == null) { // The fileName might be URL encoded. See https://silbloom.myjetbrains.com/youtrack/issue/BL-3901. var path = UrlPathString.GetFullyDecodedPath(folderPath, ref fileName); progress.WriteStatus("Reading metadata from " + fileName); if (!RobustFile.Exists(path)) // they have bigger problems, which aren't appropriate to deal with here. { imgElement.RemoveAttribute("data-copyright"); imgElement.RemoveAttribute("data-creator"); imgElement.RemoveAttribute("data-license"); Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Image " + path + " is missing"); //Debug.Fail(" (Debug only) Image " + path + " is missing"); return; } metadata = RobustIO.MetadataFromFile(path); } progress.WriteStatus("Writing metadata to HTML for " + fileName); imgElement.SetAttribute("data-copyright", String.IsNullOrEmpty(metadata.CopyrightNotice) ? "" : metadata.CopyrightNotice); imgElement.SetAttribute("data-creator", String.IsNullOrEmpty(metadata.Creator) ? "" : metadata.Creator); imgElement.SetAttribute("data-license", metadata.License == null ? "" : metadata.License.ToString()); }
/// <summary> /// Updates the value of the specified token on the specified XmlElement. /// If the value is the same, no update is made. If the new value is null /// the attribute is removed. /// </summary> private void UpdateAttribute(XmlElement root, XmlToken token, string value) { string name = GetXmlName(token); XmlNode oldValue = root.GetAttributeNode(name, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); if (oldValue == null) { if (value == null) return; else root.SetAttribute(name, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace, value); } else { if (value == null) root.RemoveAttribute(name, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace); else if (oldValue.Value != value) root.SetAttribute(name, AnnotationXmlConstants.Namespaces.BaseSchemaNamespace, value); } }
/// <summary> /// Remove keyed_name attributes to make diffing easier /// </summary> private void RemoveKeyedNameAttributes(XmlElement node) { if (node.HasAttribute("keyed_name")) node.RemoveAttribute("keyed_name"); foreach (var elem in node.Elements()) RemoveKeyedNameAttributes(elem); }
private static void ProcessReferenceTag(XmlElement phe, string value) { Debug.Assert(phe != null); Debug.Assert(!string.IsNullOrEmpty(value)); phe.RemoveAttribute(HRefAttribute); phe.InnerText = value; }
private void SetPolyLineType(XmlElement xml,PSPDEV dev) { LineType lt = new LineType(); lt.TypeName = dev.RateVolt.ToString("###") + "kV"; lt = (LineType)Services.BaseService.GetObject("SelectLineTypeByTypeName", lt); string styleValue = ""; if (lt != null) { if (string.IsNullOrEmpty(dev.OperationYear)) { styleValue = "stroke-dasharray:" + ghType + ";stroke-width:" + lt.ObligateField1 + ";"; } else { if (Convert.ToInt32(dev.OperationYear) > DateTime.Now.Year) { styleValue = "stroke-dasharray:" + ghType + ";stroke-width:" + lt.ObligateField1 + ";"; } else { styleValue = "stroke-width:" + lt.ObligateField1 + ";"; } } //string aa= ColorTranslator.ToHtml(Color.Black); styleValue = styleValue + "stroke:" + ColorTranslator.ToHtml(Color.FromArgb(Convert.ToInt32(lt.Color))); //SvgElement se = DeviceHelper.xml1; xml.RemoveAttribute("style"); xml.SetAttribute("style", styleValue); xml.SetAttribute("info-name", dev.Name); } }
/// <summary> /// Updates the attribute values for the element. /// </summary> void UpdateChangedAttributes(XmlElement changedElement) { if (changedElement != null) { foreach (WixXmlAttribute attribute in view.Attributes) { if (String.IsNullOrEmpty(attribute.Value)) { changedElement.RemoveAttribute(attribute.Name); } else { changedElement.SetAttribute(attribute.Name, attribute.Value); } } } }
/// <summary> /// Sets the value of specified attribute on the indicated context /// <see cref="XmlElement"/>. If the value is <c>null</c> then the /// attribute is removed. /// </summary> /// <param name="context">The context <see cref="XmlElement"/>.</param> /// <param name="name">The attribute name.</param> /// <param name="value">The new value or <c>null</c>.</param> public static void SetAttribute(XmlElement context, string name, string value) { if (value == null) { context.RemoveAttribute (name); } else context.SetAttribute (name, value); }
public void SetMonoDevelopProjectExtension (string section, XmlElement value) { AssertCanModify (); var elem = GetProjectExtension ("MonoDevelop"); if (elem == null) { XmlDocument doc = new XmlDocument (); elem = doc.CreateElement (null, "MonoDevelop", MSBuildProject.Schema); } value = (XmlElement) elem.OwnerDocument.ImportNode (value, true); var parent = elem; elem = parent ["Properties", MSBuildProject.Schema]; if (elem == null) { elem = parent.OwnerDocument.CreateElement (null, "Properties", MSBuildProject.Schema); parent.AppendChild (elem); XmlUtil.Indent (format, elem, true); } XmlElement sec = elem [value.LocalName]; if (sec == null) elem.AppendChild (value); else { elem.InsertAfter (value, sec); XmlUtil.RemoveElementAndIndenting (sec); } XmlUtil.Indent (format, value, false); var xmlns = value.GetAttribute ("xmlns"); if (xmlns == Schema) value.RemoveAttribute ("xmlns"); SetProjectExtension (parent); NotifyChanged (); }
public static bool updateXmlNode(MainWindow pW, XmlElement dstXe, string attrName, string newValue) { string oldValue = dstXe.GetAttribute(attrName); if (newValue != "") { dstXe.SetAttribute(attrName, newValue); } else { dstXe.RemoveAttribute(attrName); } return false; }
/// <summary> /// Updates the Text child element if it exists otherwise updates the /// Text attribute. /// </summary> void UpdateElementText(XmlElement controlElement, string text) { XmlElement textElement = (XmlElement)controlElement.SelectSingleNode("w:Text", namespaceManager); if (textElement != null) { textElement.InnerText = text; } else if (text.Length > 0) { // Set text if the control text is not an empty string. controlElement.SetAttribute("Text", text); } else { // Remove the Text attribute. controlElement.RemoveAttribute("Text"); } }
private void ToXml( ValueSetEntry entry, XmlElement element ) { // If the element passed in is null, this ValueSet doesn't currently have an // XML Element that it is associated with. This is OK. Exit Gracefully. if ( element == null ) { return; } entry.ToXml( element ); // Since this class controls the notion of defaults, write the // attributes controlling defaults here bool isDefaultAppValue = fDefaultAppEntry == entry; bool isDefaultSifValue = fDefaultSifEntry == entry; if ( isDefaultAppValue ) { if ( isDefaultSifValue ) { element.SetAttribute( "default", "both" ); element.SetAttribute( "ifnull", GetIfNull( fRenderSifDefaultIfNull ) ); } else { element.SetAttribute( "default", "inbound" ); element.SetAttribute( "ifnull", GetIfNull( fRenderAppDefaultIfNull ) ); } } else if ( isDefaultSifValue ) { element.SetAttribute( "default", "outbound" ); element.SetAttribute( "ifnull", GetIfNull( fRenderSifDefaultIfNull ) ); } else { element.RemoveAttribute( "default" ); element.RemoveAttribute( "ifnull" ); } }
static void RenameAttribute(XmlElement elem, string oldAttrName, string newAttrName) { elem.SetAttribute(newAttrName, elem.GetAttribute(oldAttrName)); elem.RemoveAttribute(oldAttrName); }
public static void RemoveRtlDir(XmlElement e) { e.RemoveAttribute("dir"); }
/// <summary> /// Sets an XML Attribute, or removes it if the value is null /// </summary> /// <param name="element"></param> /// <param name="attributeName"></param> /// <param name="value"></param> public static void SetOrRemoveAttribute(XmlElement element, string attributeName, string value) { if( value == null ) { element.RemoveAttribute( attributeName ); } else { element.SetAttribute(attributeName, value); } }
protected override XmlElement WriteData(XmlElement element) { // This outputs little more than what's necessary to create a custom game entry // Once in the file, the xml wil not need to be re-generated, so it won't need to be outputted again // This way manual updates to the xml file won't be lost ;) ID.AddAttributes(element); if (element.HasAttribute("name")) element.RemoveAttribute("name"); element.AppendChild(Locations.XML); foreach (FileType type in FileTypes.Values) { element.AppendChild(type.XML); } foreach (string con in Contributors) { element.AppendChild(Game.createElement("contributor", con)); } if (!String.IsNullOrEmpty(Comment)) element.AppendChild(Game.createElement("comment", Comment)); if (!String.IsNullOrEmpty(RestoreComment)) element.AppendChild(Game.createElement("restore_comment", RestoreComment)); return element; }
void CleanUndoData (XmlElement elem) { elem.RemoveAttribute ("undoId"); foreach (XmlNode cn in elem.ChildNodes) { XmlElement ce = cn as XmlElement; if (ce != null) CleanUndoData (ce); } }
void UpdateObject (WidgetParser parser, string topType, XmlElement objectElem, ITypeSymbol widgetClass, ITypeSymbol wrapperClass) { if (widgetClass.DeclaredAccessibility == Accessibility.Public) objectElem.RemoveAttribute ("internal"); else objectElem.SetAttribute ("internal", "true"); ListDictionary properties = new ListDictionary (); ListDictionary events = new ListDictionary (); parser.CollectMembers (widgetClass, true, topType, properties, events); if (wrapperClass != null) parser.CollectMembers (wrapperClass, false, null, properties, events); foreach (IPropertySymbol prop in properties.Values) MergeProperty (parser, objectElem, prop); foreach (IEventSymbol ev in events.Values) MergeEvent (parser, objectElem, ev); // Remove old properties ArrayList toDelete = new ArrayList (); foreach (XmlElement xprop in objectElem.SelectNodes ("itemgroups/itemgroup/property")) { if (!properties.Contains (xprop.GetAttribute ("name"))) toDelete.Add (xprop); } // Remove old signals foreach (XmlElement xevent in objectElem.SelectNodes ("signals/itemgroup/signal")) { if (!events.Contains (xevent.GetAttribute ("name"))) toDelete.Add (xevent); } foreach (XmlElement el in toDelete) { XmlElement pe = (XmlElement) el.ParentNode; pe.RemoveChild (el); if (pe.ChildNodes.Count == 0) pe.ParentNode.RemoveChild (pe); } }
public static void resetXeView(Basic uiView, out XmlElement xeView) { xeView = uiView.m_xe.OwnerDocument.CreateElement(uiView.m_xe.Name); foreach (XmlAttribute attr in uiView.m_xe.Attributes) { xeView.SetAttribute(attr.Name, attr.Value); } xeView.RemoveAttribute("x"); xeView.RemoveAttribute("y"); xeView.RemoveAttribute("visible"); xeView.RemoveAttribute("dock"); xeView.RemoveAttribute("anchor"); xeView.RemoveAttribute("anchorSelf"); xeView.SetAttribute("x", uiView.m_selScreenX.ToString()); xeView.SetAttribute("y", uiView.m_selScreenY.ToString()); xeView.SetAttribute("w", uiView.m_selW.ToString()); xeView.SetAttribute("h", uiView.m_selH.ToString()); xeView.SetAttribute("baseID", "selSkinTestCtrl"); xeView.SetAttribute("skin", uiView.m_xe.GetAttribute("skin")); }
/// <summary> /// Inspects a Permission element. /// </summary> /// <param name="element">The Permission element to inspect.</param> /// <returns>The inspected element.</returns> private XmlElement InspectPermissionElement(XmlElement element) { // if this is a FileSharePermissions element, then process it accordingly if (null != element.ParentNode && "FileShare" == element.ParentNode.LocalName) { element = this.InspectUtilElement(element); } // if this is a SecureObjects element, then process it accordingly if (null != element.Attributes["Extended"] || (null != element.ParentNode && "ServiceInstall" == element.ParentNode.LocalName)) { // remove the Extended attribute since its no longer needed if (null != element.Attributes["Extended"]) { element.RemoveAttribute("Extended"); } element = this.InspectUtilElement(element); } return element; }