/// <summary>Removes attributes, comments, and processing instructions. </summary> private static void clean(System.Xml.XmlElement elem) { System.Xml.XmlNodeList children = elem.ChildNodes; for (int i = 0; i < children.Count; i++) { System.Xml.XmlNode child = children.Item(i); if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.ProcessingInstruction || System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Comment) { elem.RemoveChild(child); } else if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Element) { clean((System.Xml.XmlElement)child); } } System.Xml.XmlNamedNodeMap attributes = (System.Xml.XmlAttributeCollection)elem.Attributes; //get names System.String[] names = new System.String[attributes.Count]; for (int i = 0; i < names.Length; i++) { names[i] = attributes.Item(i).Name; } //remove by name for (int i = 0; i < names.Length; i++) { attributes.RemoveNamedItem(names[i]); } }
/// <summary>Read Element named magic. </summary> private void ReadMagic(System.Xml.XmlElement element, MimeType mimeType) { // element.getValue(); System.String offset = null; System.String content = null; System.String type = null; System.Xml.XmlNamedNodeMap attrs = (System.Xml.XmlAttributeCollection)element.Attributes; for (int i = 0; i < attrs.Count; i++) { System.Xml.XmlAttribute attr = (System.Xml.XmlAttribute)attrs.Item(i); if (attr.Name.Equals("offset")) { offset = attr.Value; } else if (attr.Name.Equals("type")) { type = attr.Value; if (String.Compare(type, "byte", true) == 0) { type = "System.Byte"; } } else if (attr.Name.Equals("value")) { content = attr.Value; } } if ((offset != null) && (content != null)) { mimeType.AddMagic(System.Int32.Parse(offset), type, content); } }
//The function is called when expanding the entity ref. ( inside XmlEntityReference.SetParent ) internal void ExpandEntityReference(XmlEntityReference eref) { //when the ent ref is not associated w/ an entity, append an empty string text node as child _doc = eref.OwnerDocument; bool bOrigLoadingState = _doc.IsLoading; _doc.IsLoading = true; switch (eref.Name) { case "lt": eref.AppendChildForLoad(_doc.CreateTextNode("<"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "gt": eref.AppendChildForLoad(_doc.CreateTextNode(">"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "amp": eref.AppendChildForLoad(_doc.CreateTextNode("&"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "apos": eref.AppendChildForLoad(_doc.CreateTextNode("'"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "quot": eref.AppendChildForLoad(_doc.CreateTextNode("\""), _doc); _doc.IsLoading = bOrigLoadingState; return; } XmlNamedNodeMap entities = _doc.Entities; foreach (XmlEntity ent in entities) { if (Ref.Equal(ent.Name, eref.Name)) { ParsePartialContent(eref, EntitizeName(eref.Name), XmlNodeType.EntityReference); return; } } //no fit so far if (!(_doc.ActualLoadingStatus)) { eref.AppendChildForLoad(_doc.CreateTextNode(""), _doc); _doc.IsLoading = bOrigLoadingState; } else { _doc.IsLoading = bOrigLoadingState; throw new XmlException(SR.Xml_UndeclaredParEntity, eref.Name); } }
/// <summary>Read Element named mime-type. </summary> private MimeType ReadMimeType(System.Xml.XmlElement element) { System.String name = null; System.String description = null; MimeType type = null; System.Xml.XmlNamedNodeMap attrs = (System.Xml.XmlAttributeCollection)element.Attributes; for (int i = 0; i < attrs.Count; i++) { System.Xml.XmlAttribute attr = (System.Xml.XmlAttribute)attrs.Item(i); if (attr.Name.Equals("name")) { name = attr.Value; } else if (attr.Name.Equals("description")) { description = attr.Value; } } if ((name == null) || (name.Trim().Equals(""))) { return(null); } try { //System.Diagnostics.Trace.WriteLine("Mime type:" + name); type = new MimeType(name); } catch (MimeTypeException mte) { // Mime Type not valid... just ignore it System.Diagnostics.Trace.WriteLine(mte.ToString() + " ... Ignoring!"); return(null); } type.Description = description; System.Xml.XmlNodeList nodes = element.ChildNodes; for (int i = 0; i < nodes.Count; i++) { System.Xml.XmlNode node = nodes.Item(i); if (System.Convert.ToInt16(node.NodeType) == (short)System.Xml.XmlNodeType.Element) { System.Xml.XmlElement nodeElement = (System.Xml.XmlElement)node; if (nodeElement.Name.Equals("ext")) { ReadExt(nodeElement, type); } else if (nodeElement.Name.Equals("magic")) { ReadMagic(nodeElement, type); } } } return(type); }
internal XmlEntity GetEntityNode(String name) { if (DocumentType != null) { XmlNamedNodeMap entites = DocumentType.Entities; if (entites != null) { return((XmlEntity)(entites.GetNamedItem(name))); } } return(null); }
// Constructor. internal XmlDocumentType(XmlNode parent, String name, String publicId, String systemId, String internalSubset) : base(parent) { XmlNameTable nt = parent.FindOwnerQuick().NameTable; this.name = name; this.publicId = publicId; this.systemId = systemId; this.internalSubset = internalSubset; entities = new XmlNamedNodeMap(this); notations = new XmlNamedNodeMap(this); attributes = null; }
private void ImportFromDTD () { entities = new XmlNamedNodeMap (this); notations = new XmlNamedNodeMap (this); foreach (DTDEntityDeclaration decl in DTD.EntityDecls.Values) { XmlNode n = new XmlEntity (decl.Name, decl.NotationName, decl.PublicId, decl.SystemId, OwnerDocument); entities.SetNamedItem (n); } foreach (DTDNotationDeclaration decl in DTD.NotationDecls.Values) { XmlNode n = new XmlNotation (decl.LocalName, decl.Prefix, decl.PublicId, decl.SystemId, OwnerDocument); notations.SetNamedItem (n); } }
private void ImportFromDTD() { this.entities = new XmlNamedNodeMap(this); this.notations = new XmlNamedNodeMap(this); foreach (DTDNode dtdnode in this.DTD.EntityDecls.Values) { DTDEntityDeclaration dtdentityDeclaration = (DTDEntityDeclaration)dtdnode; XmlNode namedItem = new XmlEntity(dtdentityDeclaration.Name, dtdentityDeclaration.NotationName, dtdentityDeclaration.PublicId, dtdentityDeclaration.SystemId, this.OwnerDocument); this.entities.SetNamedItem(namedItem); } foreach (DTDNode dtdnode2 in this.DTD.NotationDecls.Values) { DTDNotationDeclaration dtdnotationDeclaration = (DTDNotationDeclaration)dtdnode2; XmlNode namedItem2 = new XmlNotation(dtdnotationDeclaration.LocalName, dtdnotationDeclaration.Prefix, dtdnotationDeclaration.PublicId, dtdnotationDeclaration.SystemId, this.OwnerDocument); this.notations.SetNamedItem(namedItem2); } }
private void ImportFromDTD() { entities = new XmlNamedNodeMap(this); notations = new XmlNamedNodeMap(this); foreach (DTDEntityDeclaration decl in DTD.EntityDecls.Values) { XmlNode n = new XmlEntity(decl.Name, decl.NotationName, decl.PublicId, decl.SystemId, OwnerDocument); entities.SetNamedItem(n); } foreach (DTDNotationDeclaration decl in DTD.NotationDecls.Values) { XmlNode n = new XmlNotation(decl.LocalName, decl.Prefix, decl.PublicId, decl.SystemId, OwnerDocument); notations.SetNamedItem(n); } }
/// <summary> /// XmlNamedNodeMap에 Node를 추가한다. /// </summary> /// <returns>실패시 null 반환</returns> public XmlNode SetNamedItem(XmlNamedNodeMap nodeMap, string name, string value) { if(nodeMap != null && name != null) { XmlNode node = CreateAttribute(name); if(value != null) node.Value = value; SetNamedItem(nodeMap, node); return node; } return null; }
/// <summary> /// XmlNamedNodeMap에 Node를 추가한다. /// </summary> /// <param name="node"></param> /// <param name="nodeMap"></param> /// <returns>실패시 null 반환</returns> public XmlNode SetNamedItem(XmlNamedNodeMap nodeMap, XmlNode node) { if(nodeMap != null && node != null) return nodeMap.SetNamedItem(node); return null; }
/// <summary> /// NamedNodeMap(대부분 XmlAttributeCollection)에서 해당 node를 삭제한다. /// </summary> /// <param name="nodeMap"></param> /// <param name="nodeName"></param> /// <returns></returns> public XmlNode RemoveNamedItem(XmlNamedNodeMap nodeMap, string nodeName) { return nodeMap.RemoveNamedItem(nodeName); }
/// <summary> /// NamedNodeMap에서 해당 node를 삭제한다. /// </summary> public XmlNode RemoveNamedItem(XmlNamedNodeMap nodeMap, XmlNode node) { return nodeMap.RemoveNamedItem(node.Name); }