public GetElementById ( string elementId ) : |
||
elementId | string | |
return |
public XmlNode GetNodeByUri(string absoluteUrl) { absoluteUrl = absoluteUrl.Trim(); if (absoluteUrl.StartsWith("#") || absoluteUrl.StartsWith("\"#")) { absoluteUrl = absoluteUrl.Replace("#", "").Replace("\"", ""); return(GetElementById(absoluteUrl)); //return GetElementById(absoluteUrl.Substring(1)); } else { Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri.AbsolutePath == absoluteUri.AbsolutePath) { return(this); } else { SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlReaderSettings settings = this.GetXmlReaderSettings(); settings.CloseInput = true; //PrepareXmlResolver(settings); using (XmlReader reader = XmlReader.Create( GetResource(absoluteUri).GetResponseStream(), settings, absoluteUri.AbsolutePath)) { doc.Load(reader); } return(doc); } } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment)); return(doc.GetElementById(fragment.Substring(1))); } } }
public void TestDataImage() { string testData = "<?xml version='1.0'?>\n<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><image id='theImage' width='50' height='50' xlink:href='data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7'/></svg>"; SvgWindow wnd = new SvgWindow(50, 50, null); SvgDocument doc = new SvgDocument(wnd); doc.LoadXml(testData); SvgImageElement imgElm = doc.GetElementById("theImage") as SvgImageElement; Assert.IsNotNull(imgElm); Assert.IsTrue(!imgElm.IsSvgImage, "IsSvgImage"); Bitmap bmp = imgElm.Bitmap; Assert.AreEqual(48, bmp.Width); Assert.AreEqual(48, bmp.Height); }
public XmlNode GetNodeByUri(string absoluteUrl) { absoluteUrl = absoluteUrl.Trim(); if (absoluteUrl.StartsWith("#")) { return(GetElementById(absoluteUrl.Substring(1))); } else { Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri.AbsolutePath == absoluteUri.AbsolutePath) { return(this); } else { SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlTextReader xtr = new XmlTextReader(absoluteUri.AbsolutePath, GetResource(absoluteUri).GetResponseStream()); XmlValidatingReader vr = new XmlValidatingReader(xtr); vr.ValidationType = ValidationType.None; doc.Load(vr); return(doc); } } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment, true)); return(doc.GetElementById(fragment.Substring(1))); } } }
public XmlNode GetNodeByUri(string absoluteUrl) { if (string.IsNullOrWhiteSpace(absoluteUrl)) { return(null); } absoluteUrl = absoluteUrl.Trim().Trim(new char[] { '\"', '\'' }); if (absoluteUrl.StartsWith("#", StringComparison.OrdinalIgnoreCase)) { return(GetElementById(absoluteUrl.Substring(1))); } Uri docUri = ResolveUri(""); Uri absoluteUri = new Uri(absoluteUrl); if (absoluteUri.IsFile) { string localFile = absoluteUri.LocalPath; if (File.Exists(localFile) == false) { Trace.TraceError("GetNodeByUri: Locally referenced file not found: " + localFile); return(null); } string fileExt = Path.GetExtension(localFile); if (!string.Equals(fileExt, ".svg", StringComparison.OrdinalIgnoreCase) && !string.Equals(fileExt, ".svgz", StringComparison.OrdinalIgnoreCase)) { Trace.TraceError("GetNodeByUri: Locally referenced file not valid: " + localFile); return(null); } } if (string.Equals(absoluteUri.Scheme, "data", StringComparison.OrdinalIgnoreCase)) { Trace.TraceError("GetNodeByUri: The Uri Scheme is 'data' is not a valid XmlDode " + absoluteUri); return(null); } string fragment = absoluteUri.Fragment; if (fragment.Length == 0) { // no fragment => return entire document if (docUri != null && string.Equals(docUri.AbsolutePath, absoluteUri.AbsolutePath, StringComparison.OrdinalIgnoreCase)) { return(this); } SvgDocument doc = new SvgDocument((SvgWindow)Window); XmlReaderSettings settings = this.GetXmlReaderSettings(); settings.CloseInput = true; //PrepareXmlResolver(settings); using (XmlReader reader = XmlReader.Create(GetResource(absoluteUri).GetResponseStream(), settings, absoluteUri.AbsolutePath)) { doc.Load(reader); } return(doc); } else { // got a fragment => return XmlElement string noFragment = absoluteUri.AbsoluteUri.Replace(fragment, ""); SvgDocument doc = (SvgDocument)GetNodeByUri(new Uri(noFragment)); return(doc.GetElementById(fragment.Substring(1))); } }