// Initialize the document. private void Initialize() { baseURI = String.Empty; preserveWhitespace = false; placeholder = new XmlDocumentFragment(this); nameCache = new NameCache(implementation.nameTable); }
public CleanResults(DateTime startOfScan, DateTime endOfScan, string cleanHTML, XmlDocumentFragment XMLDocumentFragment, ArrayList errorMessages) { this.startOfScan = startOfScan; this.endOfScan = endOfScan; this.cleanXMLDocumentFragment = XMLDocumentFragment; this.cleanHTML = cleanHTML; this.errorMessages = errorMessages; }
public TransparentXmlFragment( bool init ) { elem1 = "3"; elem3 = "4"; XmlDocument doc = new XmlDocument(); _frag = doc.CreateDocumentFragment(); XmlNode node = _frag.AppendChild( doc.CreateElement( "sub1" ) ); node.AppendChild( doc.CreateElement( "extra" ) ); _frag.AppendChild( doc.CreateElement( "sub2" ) ).InnerText = "2"; }
public void SetInnerXml () { document = new XmlDocument (); fragment = document.CreateDocumentFragment (); fragment.InnerXml = "<foo /><bar><child /></bar><baz />"; AssertEquals ("foo", fragment.FirstChild.Name); AssertEquals ("bar", fragment.FirstChild.NextSibling.Name); AssertEquals ("child", fragment.FirstChild.NextSibling.FirstChild.Name); AssertEquals ("baz", fragment.LastChild.Name); }
public void GetInnerXml () { // this will be also tests of TestWriteTo()/TestWriteContentTo() document = new XmlDocument (); fragment = document.CreateDocumentFragment (); fragment.AppendChild (document.CreateElement ("foo")); fragment.AppendChild (document.CreateElement ("bar")); fragment.AppendChild (document.CreateElement ("baz")); AssertEquals ("#Simple", "<foo /><bar /><baz />", fragment.InnerXml); }
public static XmlNode CreateTemporaryDomNode() { string tmpName = "tmp"; if (tmpFragment == null) { tmpFragment = GetTemporaryDocument().CreateDocumentFragment(); tmpDocument.AppendChild(tmpFragment); } XmlNode node = GetTemporaryDocument().CreateElement(tmpName); tmpFragment.AppendChild(node); return node; }
public void AppendChildToFragment () { document = new XmlDocument (); fragment = document.CreateDocumentFragment (); document.LoadXml ("<html><head></head><body></body></html>"); XmlElement el = document.CreateElement ("p"); el.InnerXml = "Test Paragraph"; // appending element to fragment fragment.AppendChild (el); AssertNotNull ("#AppendChildToFragment.Element", fragment.FirstChild); AssertNotNull ("#AppendChildToFragment.Element.Children", fragment.FirstChild.FirstChild); AssertEquals ("#AppendChildToFragment.Element.Child.Text", "Test Paragraph", fragment.FirstChild.FirstChild.Value); }
public void AppendFragmentToElement () { document = new XmlDocument (); fragment = document.CreateDocumentFragment (); document.LoadXml ("<html><head></head><body></body></html>"); XmlElement body = document.DocumentElement.LastChild as XmlElement; fragment.AppendChild (document.CreateElement ("p")); fragment.AppendChild (document.CreateElement ("div")); // appending fragment to element body.AppendChild (fragment); AssertNotNull ("#AppendFragmentToElement.Exist", body.FirstChild); AssertEquals ("#AppendFragmentToElement.ChildIsElement", XmlNodeType.Element, body.FirstChild.NodeType); AssertEquals ("#AppendFragmentToElement.FirstChild", "p", body.FirstChild.Name); AssertEquals ("#AppendFragmentToElement.LastChild", "div", body.LastChild.Name); }
public void AppendFragmentToElement () { document = new XmlDocument (); fragment = document.CreateDocumentFragment (); document.LoadXml ("<html><head></head><body></body></html>"); XmlElement body = document.DocumentElement.LastChild as XmlElement; fragment.AppendChild (document.CreateElement ("p")); fragment.AppendChild (document.CreateElement ("div")); // appending fragment to element XmlNode ret = body.AppendChild (fragment); Assert.IsNotNull (body.FirstChild, "#AppendFragmentToElement.Exist"); Assert.AreEqual (XmlNodeType.Element, body.FirstChild.NodeType, "#AppendFragmentToElement.ChildIsElement"); Assert.AreEqual ("p", body.FirstChild.Name, "#AppendFragmentToElement.FirstChild"); Assert.AreEqual ("div", body.LastChild.Name, "#AppendFragmentToElement.LastChild"); Assert.AreEqual ("p", ret.LocalName, "#AppendFragmentToElement.ReturnValue"); }
public void core0004A() { string computedValue = ""; string expectedValue = "domestic"; System.Xml.XmlAttribute domesticAttr = null; testResults results = new testResults("Core0004A"); try { results.description = "Attr objects may be associated with Element " + "nodes contained within a DocumentFragment."; System.Xml.XmlDocumentFragment docFragment = util.getDOMDocument().CreateDocumentFragment(); System.Xml.XmlElement newElement = (System.Xml.XmlElement)util.createNode(util.ELEMENT_NODE, "element1"); // // The new DocumentFragment is empty upon creation. Set an attribute for // a newly created element and add the element to the documentFragment. // newElement.SetAttribute("domestic", "Yes"); docFragment.AppendChild(newElement); // // Access the attributes of the only child of the documentFragment // domesticAttr = (System.Xml.XmlAttribute)docFragment.FirstChild.Attributes.Item(0); computedValue = domesticAttr.Name; } catch (System.Exception ex) { computedValue = "Exception " + ex.Message; } // // Write out results // results.expected = expectedValue; results.actual = computedValue; util.resetData(); Assert.AreEqual(results.expected, results.actual); // return results; }
private ulong ComputeHashXmlFragment( XmlDocumentFragment frag ) { HashAlgorithm ha = new HashAlgorithm(); ComputeHashXmlChildren( ha, frag ); return ha.Hash; }
internal DOMDocumentFragment(XmlDocumentFragment/*!*/ xmlDocumentFragment) : base(ScriptContext.CurrentContext, true) { this.XmlDocumentFragment = xmlDocumentFragment; }
private void InitBlock() { dom = document.CreateDocumentFragment(); }
public abstract void SaveToXml(XmlDocumentFragment fragment);
private static void WorkWeekDay(XmlDocument xmlPrjDoc, XmlDocumentFragment doc, int i, int fromTime, int toTime) { XmlElement elem = xmlPrjDoc.CreateElement("WorkingTime"); CheckWorkTimes(xmlPrjDoc,doc, AddDay((byte)i)); string s= "<FromTime>"+GetTimeString(fromTime)+"</FromTime>"+ "<ToTime>"+GetTimeString(toTime)+"</ToTime>"; elem.InnerXml=s; doc.SelectSingleNode(String.Format("Calendar/WeekDays/WeekDay[{0}]/WorkingTimes", AddDay((byte)i))).AppendChild(elem); doc.SelectSingleNode(String.Format("Calendar/WeekDays/WeekDay[{0}]/DayWorking", AddDay((byte)i))).InnerText=1.ToString(); }
private static void CheckWorkTimes(XmlDocument xmlPrjDoc, XmlDocumentFragment doc, int i) { if(doc.SelectSingleNode(String.Format("Calendar/WeekDays/WeekDay[{0}]/WorkingTimes", i))==null) { XmlElement WTNode = xmlPrjDoc.CreateElement("WorkingTimes"); doc.SelectSingleNode(String.Format("Calendar/WeekDays/WeekDay[{0}]", i)).AppendChild(WTNode); } }
private static void WorkExceptionDay(XmlDocument xmlPrjDoc, XmlDocumentFragment doc, DateTime fromDate, DateTime toDate, int fromTime, int toTime) { XmlElement elem = xmlPrjDoc.CreateElement("WeekDay"); string s= "<DayType>0</DayType>"+ "<DayWorking>1</DayWorking>"+ "<TimePeriod>"+ "<FromDate>"+XmlConvert.ToString(fromDate, DateTimeFormatString)+"</FromDate>"+ "<ToDate>"+XmlConvert.ToString(toDate.AddSeconds(23*3600+59*60+59), DateTimeFormatString)+"</ToDate>"+ "</TimePeriod>"+ "<WorkingTimes>"+ "<WorkingTime>"+ "<FromTime>"+GetTimeString(fromTime)+"</FromTime>"+ "<ToTime>"+GetTimeString(toTime)+"</ToTime>"+ "</WorkingTime>"+ "</WorkingTimes>"; elem.InnerXml=s; doc.SelectSingleNode("Calendar/WeekDays").AppendChild(elem); }
private static void WorkingException(XmlDocument xmlPrjDoc, XmlDocumentFragment doc, DateTime fromDate, DateTime toDate, int fromTime, int toTime) { if(fromTime<0 && toTime<=0) //полностью во вчерашний день { WorkExceptionDay(xmlPrjDoc,doc, fromDate.AddDays(-1), toDate.AddDays(-1), fromTime+1440, toTime+1440); } if(fromTime<0 && toTime>0) //частично во вчерашний день, частично в сегодн¤шний { WorkExceptionDay(xmlPrjDoc,doc, fromDate.AddDays(-1),toDate.AddDays(-1), fromTime+1440, 1440); WorkExceptionDay(xmlPrjDoc,doc, fromDate, toDate, 0, toTime); } if(fromTime>=0 && fromTime<1440 && toTime>0 && toTime<=1440) //полностью в сегодн¤шний { WorkExceptionDay(xmlPrjDoc,doc, fromDate, toDate, fromTime, toTime); } if(fromTime>0 && fromTime<1440 && toTime>1440) //частично в сегодн¤шнем дне, частично в завтрашнем { WorkExceptionDay(xmlPrjDoc,doc, fromDate, toDate, fromTime, 1440); WorkExceptionDay(xmlPrjDoc,doc, fromDate.AddDays(1), toDate.AddDays(1), 0, toTime-1440); } if(fromTime>=1440 && toTime>1440) //полностью в завтрашнем дне { WorkExceptionDay(xmlPrjDoc,doc, fromDate.AddDays(1), toDate.AddDays(1), fromTime-1440, toTime-1440); } }
public override void SaveToXml(XmlDocumentFragment fragment) { fragment.InnerXml = content; }
public void InnerText () { document = new XmlDocument (); fragment = document.CreateDocumentFragment (); string text = "<foo /><bar><child /></bar><baz />"; fragment.InnerText = text; Assert.AreEqual (text, fragment.InnerText); }
protected void MoveChildNodes(XmlDocumentFragment fragment, XmlElement element) { while (element.ChildNodes.Count > 0) { fragment.AppendChild(element.ChildNodes[0]); } }
protected virtual bool FragmentSet(string xPath, bool append, XmlDocumentFragment frag) { try { XmlNodeList data = Payload.SelectNodes(xPath, NSM); XmlNode rootNode = Payload.SelectSingleNode(XPSc("r"), NSM); if (rootNode == null) return false; if (data.Count == 0) { rootNode.AppendChild(frag); return true; } XmlNode sibling = data[append ? data.Count - 1 : 0]; sibling.ParentNode.InsertAfter(frag, sibling); if (!append) sibling.ParentNode.RemoveChild(sibling); return true; } catch (Exception ex) { throw ex; } }
public virtual XmlNode ImportNode(XmlNode node, bool deep) { if (node == null) { throw new NullReferenceException("Null node cannot be imported."); } switch (node.NodeType) { case XmlNodeType.Attribute: XmlAttribute srcAtt = node as XmlAttribute; XmlAttribute dstAtt = this.CreateAttribute(srcAtt.Prefix, srcAtt.LocalName, srcAtt.NamespaceURI); for (XmlNode n = srcAtt.FirstChild; n != null; n = n.NextSibling) { dstAtt.AppendChild(this.ImportNode(n, deep)); } return(dstAtt); case XmlNodeType.CDATA: return(this.CreateCDataSection(node.Value)); case XmlNodeType.Comment: return(this.CreateComment(node.Value)); case XmlNodeType.Document: throw new XmlException("Document cannot be imported."); case XmlNodeType.DocumentFragment: XmlDocumentFragment df = this.CreateDocumentFragment(); if (deep) { for (XmlNode n = node.FirstChild; n != null; n = n.NextSibling) { df.AppendChild(this.ImportNode(n, deep)); } } return(df); case XmlNodeType.DocumentType: throw new XmlException("DocumentType cannot be imported."); case XmlNodeType.Element: XmlElement src = (XmlElement)node; XmlElement dst = this.CreateElement(src.Prefix, src.LocalName, src.NamespaceURI); for (int i = 0; i < src.Attributes.Count; i++) { XmlAttribute attr = src.Attributes [i]; if (attr.Specified) // copies only specified attributes { dst.SetAttributeNode((XmlAttribute)this.ImportNode(attr, deep)); } } if (deep) { for (XmlNode n = src.FirstChild; n != null; n = n.NextSibling) { dst.AppendChild(this.ImportNode(n, deep)); } } return(dst); case XmlNodeType.EndElement: throw new XmlException("Illegal ImportNode call for NodeType.EndElement"); case XmlNodeType.EndEntity: throw new XmlException("Illegal ImportNode call for NodeType.EndEntity"); case XmlNodeType.EntityReference: return(this.CreateEntityReference(node.Name)); case XmlNodeType.None: throw new XmlException("Illegal ImportNode call for NodeType.None"); case XmlNodeType.ProcessingInstruction: XmlProcessingInstruction pi = node as XmlProcessingInstruction; return(this.CreateProcessingInstruction(pi.Target, pi.Data)); case XmlNodeType.SignificantWhitespace: return(this.CreateSignificantWhitespace(node.Value)); case XmlNodeType.Text: return(this.CreateTextNode(node.Value)); case XmlNodeType.Whitespace: return(this.CreateWhitespace(node.Value)); case XmlNodeType.XmlDeclaration: XmlDeclaration srcDecl = node as XmlDeclaration; return(this.CreateXmlDeclaration(srcDecl.Version, srcDecl.Encoding, srcDecl.Standalone)); default: throw new InvalidOperationException("Cannot import specified node type: " + node.NodeType); } }
/// <include file='doc\XmlDocument.uex' path='docs/doc[@for="XmlDocument.XmlDocument2"]/*' /> protected internal XmlDocument( XmlImplementation imp ): base() { this.implementation = imp; idTable = new XmlIdentityTable( this ); // force the following string instances to be default in the nametable XmlNameTable nt = this.NameTable; nt.Add( string.Empty ); nt.Add( strDocumentName ); nt.Add( strDocumentFragmentName ); nt.Add( strCommentName ); nt.Add( strTextName ); nt.Add( strCDataSectionName ); nt.Add( strEntityName ); nt.Add( strID ); nt.Add( strNonSignificantWhitespaceName ); nt.Add( strSignificantWhitespaceName ); nt.Add( strXmlns ); nt.Add( strXml ); nt.Add( strSpace ); nt.Add( strLang ); nt.Add( strReservedXmlns ); nt.Add( strEmpty ); nullNode = new XmlDocumentFragment( this ); eleIds = new XmlElementIdMap(this); loader = new XmlLoader(); _schemaInfo = null; isLoading = false; fEntRefNodesPresent = false; fIsEdited = false; fCDataNodesPresent = false; bSetResolver = false; resolver = null; this.objLock = new object(); }
private static IEnumerable ExpandIncludeNode(XmlDocument ownerDocment, string baseDirectory, List <string> parentFileList, List <string> includeFileList, XmlElement element) { string includeFileName = element.GetAttribute(PathToken); if (String.IsNullOrEmpty(includeFileName)) { return new XmlNode[] { } } ; if (!String.IsNullOrEmpty(baseDirectory) && !Path.IsPathRooted(includeFileName)) { includeFileName = Path.Combine(baseDirectory, includeFileName); } if (!String.IsNullOrEmpty(baseDirectory) && IsCircularFileExists(parentFileList, includeFileName)) { throw new XmlException(String.Format("Circular reference encountered on the {0} file.", baseDirectory)); } if (!includeFileList.Contains(includeFileName)) { includeFileList.Add(includeFileName); } XmlDocumentFragment fragment = ownerDocment.CreateDocumentFragment(); try { XmlDocument includeDoc = new XmlDocument(); includeDoc.Load(includeFileName); foreach (XmlAttribute attr in element.Attributes) { if (attr.Name != PathToken) { includeDoc.DocumentElement.SetAttribute(attr.Name, attr.Value); } } fragment.InnerXml = includeDoc.InnerXml; return(new XmlNode[] { fragment.SelectSingleNode("/*") }); } catch (XmlException) { try { using (StreamReader sr = File.OpenText(includeFileName)) fragment.InnerXml = sr.ReadToEnd(); return(fragment.SelectNodes("/*|/comment()")); } catch (Exception innerEx) { throw new XmlException(String.Format("{0}: Error loading xml file.", includeFileName), innerEx); } } catch (Exception ex) { throw new XmlException(String.Format("{0}: Error loading xml file.", includeFileName), ex); } }
static void trimWhitespace(XmlDocumentFragment fragment) { while (fragment.FirstChild != null && fragment.FirstChild.NodeType == XmlNodeType.Whitespace) fragment.RemoveChild(fragment.FirstChild); while (fragment.LastChild != null && fragment.LastChild.NodeType == XmlNodeType.Whitespace) fragment.RemoveChild(fragment.LastChild); }
/// <summary>Construct a <c>DomDestination</c> based on an existing DocumentFragment node.</summary> /// <remarks>The new data will be added as a child of the supplied node.</remarks> /// <param name="attachmentPoint">The document fragment node to which new contents will /// be attached. The new contents will be added after any existing children.</param> public DomDestination(XmlDocumentFragment attachmentPoint) { builder = new DotNetDomBuilder(); builder.setAttachmentPoint(attachmentPoint); }