//========================================================================== private void SaveCompositeProperty(XmlElement parent, MarkupProperty property) { XmlElement element = CreatePropertyElement(property); SavePropertyContent(element, property); parent.AppendChild(element); }
public Cell(MarkupProperty mp) { if (string.IsNullOrEmpty(mp.markupData)) { this.AddData(NILL_PLACEHOLDER); } else { this.AddData(mp.markupData); } if (mp.Links.Count > 0) { foreach (FootnoteProperty fnp in mp.Links) { this.FootnoteIndexer += string.Format("[{0}],", fnp.Id); } this.FootnoteIndexer = this.FootnoteIndexer.TrimEnd(','); } this.Markup = mp; this.ContextID = mp.contextRef.ContextID; if (mp.unitRef == null) { this.UnitID = string.Empty; } else { this.UnitID = mp.unitRef.UnitID; } }
private void WriteChildren(XmlWriter writer, MarkupProperty markupProp) { if (!markupProp.IsComposite) { WriteObject(null, markupProp.Value, writer, false); } else { IList collection = markupProp.Value as IList; IDictionary dictionary = markupProp.Value as IDictionary; if (collection != null) { foreach (object obj in collection) { WriteObject(null, obj, writer, false); } } else if (dictionary != null) { foreach (object key in dictionary.Keys) { WriteObject(key, dictionary[key], writer, false); } } else { WriteObject(null, markupProp.Value, writer, false); } } }
private void ResolveChildXmlNamespaces(MarkupProperty markupProp) { if (!markupProp.IsComposite) { ResolveXmlNamespaces(markupProp); } else { IList collection = markupProp.Value as IList; IDictionary dictionary = markupProp.Value as IDictionary; if (collection != null) { foreach (object obj in collection) { ResolveXmlNamespaces(obj); } } else if (dictionary != null) { foreach (object key in dictionary.Keys) { ResolveXmlNamespaces(dictionary[key]); } } else { ResolveXmlNamespaces(markupProp.Value); } } }
//========================================================================== private void SaveBindingProperty(XmlElement parent, MarkupProperty property, Binding binding) { // Bound properties are always serialized with an element so... // ...MarkupWriter.GetMarkupObjectFor() can be used to save the Binding XmlElement element = CreatePropertyElement(property); SaveObject(element, MarkupWriter.GetMarkupObjectFor(binding)); parent.AppendChild(element); }
//========================================================================== private XmlElement CreatePropertyElement(MarkupProperty property) { if (property.IsAttached) { // If this property is attached it must be a DependencyProperty return(Document.CreateElement(GetNamespacePrefix(property.DependencyProperty.OwnerType), property.Name, GetNamespaceUri(property.DependencyProperty.OwnerType))); } // Use the type of the property's component return(Document.CreateElement(GetNamespacePrefix(property.PropertyDescriptor.ComponentType), property.PropertyDescriptor.ComponentType.Name + "." + property.Name, GetNamespaceUri(property.PropertyDescriptor.ComponentType))); }
//========================================================================== private void SavePropertyContent(XmlElement parent, MarkupProperty property) { List <MarkupObject> items = new List <MarkupObject>(property.Items); if (items.Count > 0) { foreach (MarkupObject item in items) { SaveObject(parent, item); } } else { parent.InnerText = property.StringValue; } }
public void TestLoadInlineXBRLDocument1() { string fileName = @"R:\Liberty Global\20080331\XBRLUSGAAPTaxonomies-2008-03-31\XBRLUSGAAPTaxonomies-2008-03-31\ind\ci\testing.xml"; TestInstance ins1 = new TestInstance(); ArrayList errors = new ArrayList(); Assert.IsTrue(ins1.TryLoadInstanceDoc(fileName, out errors), "Instance document load should succeed"); fileName = @"R:\Liberty Global\20080331\XBRLUSGAAPTaxonomies-2008-03-31\XBRLUSGAAPTaxonomies-2008-03-31\ind\ci\testing.html"; TestInstance ins2 = new TestInstance(); errors = new ArrayList(); Assert.IsTrue(ins2.TryLoadInstanceDoc(fileName, out errors), "Instance document load should succeed"); ins1.markups.Sort(); ArrayList uniqueMarkups = new ArrayList(); foreach (MarkupProperty mp in ins2.markups) { int index = ins1.markups.BinarySearch(mp); if (index < 0) { Console.WriteLine("Found markup not in xbrl "); } } Assert.AreEqual(ins1.markups.Count, ins2.markups.Count, "should have the same markups "); Assert.AreEqual(ins1.contexts.Count, ins2.contexts.Count, "should have the same contexts "); Assert.AreEqual(ins1.units.Count, ins2.units.Count, "should have the same contexts "); ins1.markups.Sort(); ins2.markups.Sort(); for (int i = 0; i < ins1.markups.Count; i++) { MarkupProperty mp1 = ins1.markups[i] as MarkupProperty; MarkupProperty mp2 = ins2.markups[i] as MarkupProperty; if (mp1.CompareTo(mp2) != 0) { Assert.Fail("Markups are not equal " + i.ToString()); } } }
[Test] public void TestApplyScaleToMarkup() { MarkupProperty mp = new MarkupProperty(); mp.markupData = "1234"; // test 1 - no scale mp.unitRef = null; Assert.AreEqual("1234", ApplyScaleToMarkup(mp), "Incorrect value with no scale"); mp.unitRef = new UnitProperty(); mp.unitRef.Scale = 0; mp.markupData = "1"; Assert.AreEqual("1", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 1; mp.markupData = "1"; Assert.AreEqual("10", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 2; mp.markupData = "1"; Assert.AreEqual("100", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 2; mp.markupData = "1"; Assert.AreEqual("100", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 10; mp.markupData = "1"; // 1234567890 Assert.AreEqual("10000000000", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 6; mp.markupData = "12345.26"; Assert.AreEqual("12345260000", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 2; mp.markupData = "1.11"; Assert.AreEqual("111", ApplyScaleToMarkup(mp)); mp.unitRef.Scale = 1; mp.markupData = "123.11"; Assert.AreEqual("1231", ApplyScaleToMarkup(mp)); }
public static Precision WritePrecision(MarkupProperty markup, ref int previousPrecision, ref int previousPrecisionSegmented, out bool hasSegments) { hasSegments = false; if (markup.precisionDef == null) { return(null); } if (markup.contextRef.Segments != null && markup.contextRef.Segments.Count > 0) { hasSegments = true; } int oldPrecision = 0; int newPrecision = markup.precisionDef.NumberOfDigits; if (hasSegments) { oldPrecision = previousPrecisionSegmented; newPrecision = Math.Max(oldPrecision, newPrecision); if (newPrecision > oldPrecision) { previousPrecisionSegmented = newPrecision; return(markup.precisionDef); } } else { oldPrecision = previousPrecision; newPrecision = Math.Max(oldPrecision, newPrecision); if (newPrecision > oldPrecision) { previousPrecision = newPrecision; return(markup.precisionDef); } } return(null); }
//========================================================================== private void SaveAttributeProperty(XmlElement parent, MarkupProperty property) { if (property.IsAttached) { if (GetNamespacePrefix(property.DependencyProperty.OwnerType) == null) { parent.SetAttribute(property.Name, property.StringValue); } else { // Only use namespace and uri for attached properties not in the... // ...root namespace parent.SetAttribute(property.Name, GetNamespaceUri(property.DependencyProperty.OwnerType), property.StringValue); } } else { parent.SetAttribute(property.Name, property.StringValue); } }
private void ResolveXmlNamespaces(object obj) { List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentPropertyName = null; MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; string ns = _namespaceCache.GetNamespaceUriFor(objectType); if (!string.IsNullOrWhiteSpace(ns)) { string prefix = _namespaceCache.GetDefaultPrefixFor(ns); _dicNamespaceMap[ns] = new NamespaceMap(prefix, ns); } //Look for CPA info in our cache that keeps contentProperty names per Type //If it doesn't have an entry, go get the info and store it. if (!_contentProperties.ContainsKey(objectType)) { string lookedUpContentProperty = string.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; //Once content property is found, come out of the loop. break; } } _contentProperties.Add(objectType, lookedUpContentProperty); } contentPropertyName = _contentProperties[objectType]; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (markupProperty.Name != contentPropertyName) { if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { //Bug Fix DX-0120123 if (markupProperty.DependencyProperty != null) { string ns1 = _namespaceCache.GetNamespaceUriFor( markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetDefaultPrefixFor(ns1); if (!string.IsNullOrWhiteSpace(prefix1)) { _dicNamespaceMap[ns1] = new NamespaceMap(prefix1, ns1); } } } else if (markupProperty.Value.GetType() == _nullType) { } else { propertyElements.Add(markupProperty); } } else { contentProperty = markupProperty; } } if (contentProperty != null || propertyElements.Count > 0 || contentString != string.Empty) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetNamespaceUriFor(markupObj.ObjectType); if (!string.IsNullOrWhiteSpace(ns2)) { string prefix2 = _namespaceCache.GetDefaultPrefixFor(ns2); _dicNamespaceMap[ns2] = new NamespaceMap(prefix2, ns2); } ResolveChildXmlNamespaces(markupProp); } if (contentProperty != null) { if (!(contentProperty.Value is String)) { ResolveChildXmlNamespaces(contentProperty); } } } }
private void WriteProperties(XmlTextWriter writer, MarkupObject markupObj) { List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (IsContentProperty(markupObj, markupProperty)) { contentProperty = markupProperty; continue; } if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.Value == null ? string.Empty : markupProperty.Value.ToString(); if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1); if (string.IsNullOrEmpty(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(prefix1 + ":" + markupProperty.Name, temp); } } else { DependencyProperty dependencyProperty = markupProperty.DependencyProperty; Type ownerType = dependencyProperty == null ? null : dependencyProperty.OwnerType; if (markupProperty.Name == "Name" && ownerType != null && NamespaceCache.GetAssemblyNameFromType(ownerType).Equals("PresentationFramework")) { writer.WriteAttributeString("x:" + markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, temp); } } } else if (markupProperty.Value.GetType() == typeof(NullExtension)) { writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } else { propertyElements.Add(markupProperty); } } if (contentProperty != null || propertyElements.Count > 0 || !string.IsNullOrEmpty(contentString)) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetXmlNamespace(markupObj.ObjectType); string prefix2 = _namespaceCache.GetPrefixForNamespace(ns2); string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; WriteStartElement(writer, prefix2, propElementName); WriteChildren(writer, markupProp); writer.WriteEndElement(); } if (!string.IsNullOrEmpty(contentString)) { writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { writer.WriteValue(contentProperty.StringValue); } else { WriteChildren(writer, contentProperty); } } } }
private void WriteObject(object key, object obj, XmlWriter writer, bool isRoot) { List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentPropertyName = null; MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; string ns = _namespaceCache.GetNamespaceUriFor(objectType); string prefix = _namespaceCache.GetDefaultPrefixFor(ns); if (isRoot) { if (string.IsNullOrWhiteSpace(prefix)) { if (string.IsNullOrWhiteSpace(ns)) { writer.WriteStartElement(markupObj.ObjectType.Name, NamespaceCache.DefaultNamespace); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, NamespaceCache.DefaultNamespace); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, ns); } } else { writer.WriteStartElement(prefix, markupObj.ObjectType.Name, ns); } writer.WriteAttributeString("xmlns", "x", NamespaceCache.XmlnsNamespace, NamespaceCache.XamlNamespace); foreach (NamespaceMap map in _dicNamespaceMap.Values) { if (!string.IsNullOrWhiteSpace(map.Prefix) && !string.Equals(map.Prefix, "x")) { writer.WriteAttributeString("xmlns", map.Prefix, NamespaceCache.XmlnsNamespace, map.XmlNamespace); } } } else { //TODO: Fix - the best way to handle this case... if (markupObj.ObjectType.Name == "PathFigureCollection" && markupObj.Instance != null) { WriteState writeState = writer.WriteState; if (writeState == WriteState.Element) { //writer.WriteAttributeString("Figures", // markupObj.Instance.ToString()); writer.WriteAttributeString("Figures", System.Convert.ToString(markupObj.Instance, _culture)); } else { if (string.IsNullOrWhiteSpace(prefix)) { writer.WriteStartElement("PathGeometry.Figures"); } else { writer.WriteStartElement("PathGeometry.Figures", ns); } //writer.WriteString(markupObj.Instance.ToString()); writer.WriteString(System.Convert.ToString( markupObj.Instance, _culture)); writer.WriteEndElement(); } return; } else { if (string.IsNullOrWhiteSpace(prefix)) { writer.WriteStartElement(markupObj.ObjectType.Name); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); } } } // Add the x:Name for object like Geometry/Drawing not derived from FrameworkElement... DependencyObject dep = obj as DependencyObject; if (dep != null) { string nameValue = dep.GetValue(FrameworkElement.NameProperty) as string; if (!string.IsNullOrWhiteSpace(nameValue) && !(dep is FrameworkElement)) { writer.WriteAttributeString("x", "Name", NamespaceCache.XamlNamespace, nameValue); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x", "Key", NamespaceCache.XamlNamespace, keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException( "Sample XamlWriter cannot yet handle keys that aren't strings"); } } //Look for CPA info in our cache that keeps contentProperty names per Type //If it doesn't have an entry, go get the info and store it. if (!_contentProperties.ContainsKey(objectType)) { string lookedUpContentProperty = string.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; //Once content property is found, come out of the loop. break; } } _contentProperties.Add(objectType, lookedUpContentProperty); } contentPropertyName = _contentProperties[objectType]; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (markupProperty.Name != contentPropertyName) { if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.StringValue; if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetNamespaceUriFor(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetDefaultPrefixFor(ns1); if (temp.IndexOfAny("{}".ToCharArray()) >= 0) { temp = "{}" + temp; } if (string.IsNullOrWhiteSpace(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, ns1, temp); } } else { if (markupProperty.Name == "FontUri" && (_wpfSettings != null && _wpfSettings.IncludeRuntime)) { string fontUri = temp.ToLower(); fontUri = fontUri.Replace(_windowsDir, _windowsPath); StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.Append("svg"); builder.Append(":"); builder.Append("SvgFontUri "); builder.Append(fontUri.Replace('\\', '/')); builder.Append("}"); writer.WriteAttributeString(markupProperty.Name, builder.ToString()); } else { if (temp.IndexOfAny("{}".ToCharArray()) >= 0) { temp = "{}" + temp; } writer.WriteAttributeString(markupProperty.Name, temp); } } } else if (markupProperty.Value.GetType() == _nullType) { if (_nullExtension) { writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } } else { propertyElements.Add(markupProperty); } } else { contentProperty = markupProperty; } } if (contentProperty != null || propertyElements.Count > 0 || contentString != string.Empty) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetNamespaceUriFor(markupObj.ObjectType); string prefix2 = null; if (!string.IsNullOrWhiteSpace(ns2)) { prefix2 = _namespaceCache.GetDefaultPrefixFor(ns2); } string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; if (string.IsNullOrWhiteSpace(prefix2)) { writer.WriteStartElement(propElementName); } else { writer.WriteStartElement(prefix2, propElementName, ns2); } WriteChildren(writer, markupProp); writer.WriteEndElement(); } if (contentString != string.Empty) { writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { writer.WriteValue(contentProperty.StringValue); } else { WriteChildren(writer, contentProperty); } } } writer.WriteEndElement(); }
public void CreateFromXml() { string startXml = @"<?xml version=""1.0"" encoding=""utf-16""?> <?xml-stylesheet type=""text/xsl"" href=""Test.xsl""?> <!--XBRLParser message--> <!--Based on XBRL 2.1--> <!--Created on SomeDate--> <xbrl xmlns=""http://www.xbrl.org/2003/instance"" xmlns:link=""http://www.xbrl.org/2003/linkbase"" xmlns:xlink=""http://www.w3.org/1999/xlink"" xmlns:usfr_pt=""http://www.xbrl.org/2003/usfr"" xmlns:iso4217=""http://www.xbrl.org/2003/iso4217""> <link:schemaRef xlink:type=""simple"" xlink:href=""test.xsd"" /> <!--Context Section--> <context id=""current_AsOf""> <entity> <identifier scheme=""http://www.rivetsoftware.com"">Rivet</identifier> </entity> <period> <instant>2003-12-31</instant> </period> </context> <!--Unit Section--> <unit id=""u1""> <!--Scale: 2--> <measure>iso4217:USD</measure> </unit> <!--Element Section--> <!--Document address: Excel - Sheet1!$A$1--> <usfr_pt:element1 contextRef=""current_AsOf"" unitRef=""u1"" decimals=""10"">1234500</usfr_pt:element1> </xbrl>"; XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(startXml); XmlNamespaceManager theManager = new XmlNamespaceManager(xDoc.NameTable); theManager.AddNamespace("link2", "http://www.xbrl.org/2003/instance"); theManager.AddNamespace("usfr_pt", "http://www.xbrl.org/2003/usfr"); ContextProperty cp = new ContextProperty("current_AsOf"); cp.EntityValue = "Rivet"; cp.EntitySchema = "http://www.rivetsoftware.com"; cp.PeriodType = Element.PeriodType.instant; cp.PeriodStartDate = new DateTime(2003, 12, 31); ArrayList contexts = new ArrayList( ); contexts.Add(cp); UnitProperty up = new UnitProperty("u1", UnitProperty.UnitTypeCode.Standard); up.StandardMeasure.MeasureNamespace = "iso4217"; up.StandardMeasure.MeasureSchema = "http://www.xbrl.org/2003/iso4217"; up.StandardMeasure.MeasureValue = "USD"; MarkupProperty realMP = new MarkupProperty(); realMP.contextRef = cp; realMP.unitRef = up; realMP.elementId = "usfr_pt_element1"; realMP.element = new Node(new Element("element1")); realMP.markupData = "1234500"; realMP.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 10); ArrayList units = new ArrayList(); units.Add(up); XmlNodeList elemList = xDoc.SelectNodes("//usfr_pt:element1", theManager); Assert.AreEqual(1, elemList.Count, "elem not found"); MarkupProperty mp = null; ArrayList errors = new ArrayList(); Assert.IsTrue(MarkupProperty.TryCreateFromXml(0, elemList, contexts, units, out mp, ref errors), "markup property not created"); Assert.IsTrue(mp.Equals(realMP), "elem different from the real deal"); Assert.AreEqual("http://www.xbrl.org/2003/usfr", mp.elementNamespace, "namespace wrong"); }
private bool IsContentProperty(MarkupObject markupObj, MarkupProperty markupProperty) { return(markupProperty.Name == GetContentPropertyName(markupObj)); }
private void WriteObject(object key, object obj, XmlTextWriter writer, bool isRoot) { MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; _namespaceCache.GetXmlNamespace(objectType); string ns = _namespaceCache.GetXmlNamespace(objectType); string prefix = _namespaceCache.GetPrefixForNamespace(ns); WriteStartElement(writer, prefix, markupObj.ObjectType.Name); if (isRoot) { foreach (NamespaceMap map in _namespaceMaps.Values) { if (string.IsNullOrEmpty(map.Prefix)) { writer.WriteAttributeString("xmlns", map.XmlNamespace); } else { writer.WriteAttributeString("xmlns:" + map.Prefix, map.XmlNamespace); } } if (!_namespaceMaps.ContainsKey(NamespaceCache.XamlNamespace)) { writer.WriteAttributeString("xmlns:x", NamespaceCache.XamlNamespace); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x:Key", keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException(); } } List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentString = string.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (IsContentProperty(markupObj, markupProperty)) { contentProperty = markupProperty; continue; } if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.Value == null ? string.Empty : _formatterConverter.ToString(markupProperty.Value); if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1); if (string.IsNullOrEmpty(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(prefix1 + ":" + markupProperty.Name, temp); } } else { if (markupProperty.Name == "Name" && NamespaceCache.GetAssemblyNameFromType(markupProperty.DependencyProperty.OwnerType).Equals("PresentationFramework")) { writer.WriteAttributeString("x:" + markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, temp); } } } else if (markupProperty.Value.GetType() == typeof(NullExtension)) { writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } else { propertyElements.Add(markupProperty); } } if (contentProperty != null || propertyElements.Count > 0 || !string.IsNullOrEmpty(contentString)) { foreach (MarkupProperty markupProp in propertyElements) { string ns2 = _namespaceCache.GetXmlNamespace(markupObj.ObjectType); string prefix2 = _namespaceCache.GetPrefixForNamespace(ns2); string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; WriteStartElement(writer, prefix2, propElementName); WriteChildren(writer, markupProp); writer.WriteEndElement(); } if (!string.IsNullOrEmpty(contentString)) { writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { writer.WriteValue(contentProperty.StringValue); } else { WriteChildren(writer, contentProperty); } } } writer.WriteEndElement(); }
//========================================================================== private void SaveProperty(XmlElement parent, MarkupObject markupObject, MarkupProperty property) { Binding binding = null; if (property.DependencyProperty != null) { // If this property is a DependencyProperty markupObject.Instance... // ...must be a DepedencyObject binding = BindingOperations.GetBinding(markupObject.Instance as DependencyObject, property.DependencyProperty); } if (binding != null) { SaveBindingProperty(parent, property, binding); } else { string content_property_name = null; // Get the content property of markupObject.Instance... if (property.PropertyDescriptor == null) { // SavePropertyContent(parent, property); //return; SaveAttributeProperty(parent, property); return; } if (property.PropertyDescriptor.GetType().ToString() == "System.ComponentModel.ReflectPropertyDescriptor") { //bool breaker = false; if (property.PropertyType.Name == "Object") { if (!property.IsAttached) { /*foreach (var item in property.Attributes) * { * if (item is System.Runtime.InteropServices.ClassInterfaceAttribute) * { * breaker = true; * } * }*/ //if (property.IsComposite) { try { if (property.IsComposite) //if (property.StringValue == null) { } } catch (Exception) { //SaveCompositeProperty(parent, property); return; } } } } // SavePropertyContent(parent, property); //return; //SaveAttributeProperty(parent, property); //return; } //try { object[] attributes = property.PropertyDescriptor.ComponentType.GetCustomAttributes(typeof(ContentPropertyAttribute), true); if (attributes.Length > 0) { ContentPropertyAttribute attribute = attributes[attributes.Length - 1] as ContentPropertyAttribute; content_property_name = attribute.Name; } if (content_property_name == property.Name) { // Only store the property's content SavePropertyContent(parent, property); } else if (property.IsComposite) { // Save property using its own element SaveCompositeProperty(parent, property); } else { // Save as attribute SaveAttributeProperty(parent, property); } } /*catch (Exception ex) * { * MessageBox.Show(ex.ToString()); * }*/ } }
public void TestIsMarkupMorePreciseThanRoundedValue() { MarkupProperty mp = new MarkupProperty(); mp.markupData = "123456"; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, -3); mp.unitRef = new UnitProperty(); Assert.IsTrue(mp.IsMarkupMorePreciseThanRoundedValue()); mp.unitRef.Scale = 2; Assert.IsTrue(mp.IsMarkupMorePreciseThanRoundedValue()); mp.unitRef.Scale = 3; Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "123456000"; mp.unitRef.Scale = 0; Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "126322"; mp.unitRef.Scale = 4; Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "126322.3"; mp.unitRef.Scale = 4; Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "126322.3"; mp.unitRef.Scale = 3; Assert.IsTrue(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "567456498"; mp.unitRef.Scale = 0; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 0); Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); //some per share info mp.markupData = "1.99"; mp.unitRef.Scale = 0; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 2); Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "0.99"; mp.unitRef.Scale = 0; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 2); Assert.IsFalse(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "1.991"; mp.unitRef.Scale = 0; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 2); Assert.IsTrue(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "9.991"; mp.unitRef.Scale = 0; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 2); Assert.IsTrue(mp.IsMarkupMorePreciseThanRoundedValue()); mp.markupData = "476403"; mp.unitRef.Scale = 3; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, -6); Assert.IsTrue(mp.IsMarkupMorePreciseThanRoundedValue()); }
public void TestGetRoundedMarkedupAmount() { MarkupProperty mp = new MarkupProperty(); mp.markupData = "123456.789012"; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, -3); Assert.AreEqual(123000, mp.GetRoundedMarkedupAmount()); mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, -2); Assert.AreEqual(123500, mp.GetRoundedMarkedupAmount()); mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 0); Assert.AreEqual(123457, mp.GetRoundedMarkedupAmount()); mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 2); Assert.AreEqual(123456.79, mp.GetRoundedMarkedupAmount()); mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 4); Assert.AreEqual(123456.7890, mp.GetRoundedMarkedupAmount()); mp.markupData = "(123,456.789012)"; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, -2); Assert.AreEqual(-123500, mp.GetRoundedMarkedupAmount()); mp.markupData = "22.98"; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.None); mp.unitRef = new UnitProperty(); decimal sum = mp.GetRoundedMarkedupAmount(); Console.WriteLine(sum); mp.markupData = "3.478"; sum += mp.GetRoundedMarkedupAmount(); Assert.AreEqual(26.458, sum); //with double we get floating point error.... Console.WriteLine(sum); mp.markupData = "2.3"; sum += mp.GetRoundedMarkedupAmount(); Console.WriteLine(sum); mp.markupData = "3.478"; sum += mp.GetRoundedMarkedupAmount(); Console.WriteLine(sum); mp.markupData = "345000012"; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 0); Console.WriteLine(mp.GetRoundedMarkedupAmount()); mp.markupData = "34501.67"; mp.precisionDef = new Precision(Precision.PrecisionTypeCode.Decimals, 0); Console.WriteLine(mp.GetRoundedMarkedupAmount()); }
public void Test_AddDuplicateFootnoteResources() { xDoc = new XmlDocument(); xDoc.AppendChild(xDoc.CreateXmlDeclaration("1.0", "utf-16", null)); XmlElement root = xDoc.CreateElement(XBRL); xDoc.AppendChild(root); root.SetAttribute(DocumentBase.XMLNS, DocumentBase.XBRL_INSTANCE_URL); root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, DocumentBase.XBRL_LINKBASE_PREFIX), DocumentBase.XBRL_LINKBASE_URL); root.SetAttribute(string.Format(DocumentBase.NAME_FORMAT, DocumentBase.XMLNS, DocumentBase.XLINK_PREFIX), DocumentBase.XLINK_URI); CreateInstanceSkeleton(root, true, true); ArrayList mps = new ArrayList(); // markup property MarkupProperty mp = new MarkupProperty(); mp.Id = "Item-01"; mp.xmlElement = xDoc.CreateElement("usfr_pt:element1"); mp.address = "$c$6"; FootnoteProperty fp = new FootnoteProperty("Footnote-01", "$c$7", "en", "this is the footnote"); mp.Link(fp); mps.Add(mp); // markup property 2 MarkupProperty mp2 = new MarkupProperty(); mp2.Id = "Item-02"; mp2.xmlElement = xDoc.CreateElement("usfr_pt:element2"); mp2.address = "$b$6"; mp2.Link(fp); mps.Add(mp2); AddFootnoteLocatorsAndArcs(mps); AddFootnoteResources(mps); System.IO.StringWriter xml = new System.IO.StringWriter(); xDoc.Save(xml); Console.WriteLine(xml.ToString()); string expectedXml = @"<?xml version=""1.0"" encoding=""utf-16""?> <xbrl xmlns=""http://www.xbrl.org/2003/instance"" xmlns:link=""http://www.xbrl.org/2003/linkbase"" xmlns:xlink=""http://www.w3.org/1999/xlink""> <!--Context Section--> <!--Unit Section--> <!--Tuple Section--> <!--Element Section--> <!--Footnote Section--> <link:footnoteLink xlink:type=""extended"" xlink:role=""http://www.xbrl.org/2003/role/link""> <!--Document address: $c$6 - Element Name: usfr_pt:element1--> <link:loc xlink:type=""locator"" xlink:href=""#Item-01"" xlink:label=""Item-01_lbl"" /> <link:footnoteArc xlink:type=""arc"" xlink:arcrole=""http://www.xbrl.org/2003/arcrole/fact-footnote"" xlink:from=""Item-01_lbl"" xlink:to=""Footnote-01"" order=""1"" /> <!--Document address: $b$6 - Element Name: usfr_pt:element2--> <link:loc xlink:type=""locator"" xlink:href=""#Item-02"" xlink:label=""Item-02_lbl"" /> <link:footnoteArc xlink:type=""arc"" xlink:arcrole=""http://www.xbrl.org/2003/arcrole/fact-footnote"" xlink:from=""Item-02_lbl"" xlink:to=""Footnote-01"" order=""1"" /> <!--Document address: $c$7--> <link:footnote xlink:type=""resource"" xlink:role=""http://www.xbrl.org/2003/role/footnote"" xlink:label=""Footnote-01"" xml:lang=""en"">this is the footnote</link:footnote> </link:footnoteLink> </xbrl>"; if (System.Environment.OSVersion.Platform.ToString() == "128") { expectedXml = expectedXml.Replace("\r\n", "\n"); } Assert.AreEqual(expectedXml, xml.ToString()); }
public void ReadICI_InstanceDoc() { string ICI_INSTANCE_FILE = TestCommon.FolderRoot + "ici-instance.xml"; ArrayList errors = new ArrayList(); bool ok = TryLoadInstanceDoc(ICI_INSTANCE_FILE, out errors); if (errors.Count > 0) { errors.Sort(); foreach (ParserMessage pm in errors) { if (pm.Level == TraceLevel.Error) { Console.WriteLine(pm.Message); } else { break; } } } Assert.IsTrue(ok, "try load returned false"); Assert.AreEqual(0, errors.Count); Assert.AreEqual(1, DocumentTupleList.Count, "wrong number of tuples returned"); TupleSet theSet = (TupleSet)DocumentTupleList[0]; List <MarkupProperty> allMarkups = new List <MarkupProperty>(); theSet.GetAllMarkedupElements(ref allMarkups); Assert.AreEqual(185, allMarkups.Count, "wrong number of marked up children"); MarkupProperty mp0 = allMarkups[0]; Assert.AreEqual("ici-rr_Heading", mp0.elementId, "element 0 wrong"); Assert.AreEqual("THE SECURITIES AND EXCHANGE COMMISSION HAS NOT APPROVED OR DISAPPROVED THE FUND'S SHARES OR DETERMINED WHETHER THIS PROSPECTUS IS ACCURATE OR COMPLETE. ANYONE WHO TELLS YOU OTHERWISE IS COMMITTING A CRIME.", mp0.markupData, "element 0 data wrong"); Assert.AreEqual("ici-rr:Prospectus", mp0.TupleParentList[2], "element 0 parent 0 wrong"); Assert.AreEqual("ici-rr:RiskReturn", mp0.TupleParentList[1], "element 0 parent 1 wrong"); Assert.AreEqual("ici-rr:IntroductionHeading", mp0.TupleParentList[0], "element 0 parent 2 wrong"); MarkupProperty mp1 = allMarkups[1]; Assert.AreEqual("ici-rr_Heading", mp1.elementId, "element 1 wrong"); Assert.AreEqual("RISK &RETURN SUMMARY", mp1.markupData, "element 1 data wrong"); Assert.AreEqual("ici-rr:Prospectus", mp1.TupleParentList[2], "element 0 parent 0 wrong"); Assert.AreEqual("ici-rr:RiskReturn", mp1.TupleParentList[1], "element 0 parent 1 wrong"); Assert.AreEqual("ici-rr:RiskReturnHeading", mp1.TupleParentList[0], "element 0 parent 2 wrong"); MarkupProperty mp4 = allMarkups[4]; Assert.AreEqual("ici-rr_Heading", mp4.elementId, "element 4 wrong"); Assert.AreEqual("PRINCIPAL INVESTMENT POLICIES AND STRATEGIES", mp4.markupData, "element 4 data wrong"); Assert.AreEqual("ici-rr:Prospectus", mp4.TupleParentList[3], "element 0 parent 0 wrong"); Assert.AreEqual("ici-rr:RiskReturn", mp4.TupleParentList[2], "element 0 parent 1 wrong"); Assert.AreEqual("ici-rr:StrategySection", mp4.TupleParentList[1], "element 4 parent 2 wrong"); Assert.AreEqual("ici-rr:StrategyHeading", mp4.TupleParentList[0], "element 4 parent 3 wrong"); MarkupProperty mp7 = allMarkups[7]; Assert.AreEqual("ici-rr_Paragraph", mp7.elementId, "element 7 wrong"); Assert.AreEqual("The fund's investments may include securities traded in the over-the-counter markets. The fund may invest up to 25% of its assets in the securities of a single issuer.", mp7.markupData, "element7 data wrong"); Assert.AreEqual("ici-rr:Prospectus", mp7.TupleParentList[3], "element 7 parent 0 wrong"); Assert.AreEqual("ici-rr:RiskReturn", mp7.TupleParentList[2], "element 7 parent 1 wrong"); Assert.AreEqual("ici-rr:StrategySection", mp7.TupleParentList[1], "element 7 parent 2 wrong"); Assert.AreEqual("ici-rr:StrategyNarrativeParagraph", mp7.TupleParentList[0], "element 7 parent 3 wrong"); foreach (ContextProperty cp in this.contexts) { foreach (Segment seg in cp.Segments) { Assert.IsNotNull(seg.DimensionInfo, "Dimension info should not be null"); Assert.AreEqual("ici-rr_RegistrantDimension", seg.DimensionInfo.dimensionId); Console.WriteLine(seg.ToString()); } } }
public void WriteObject(object key, object obj, XmlWriter writer, bool isRoot) { var doc = xmldoc.DocumentElement; List <MarkupProperty> propertyElements = new List <MarkupProperty>(); MarkupProperty contentProperty = null; string contentPropertyName = null; MarkupObject markupObj = MarkupWriter.GetMarkupObjectFor(obj); Type objectType = markupObj.ObjectType; string ns = _namespaceCache.GetNamespaceUriFor(objectType); string prefix = _namespaceCache.GetDefaultPrefixFor(ns); if (isRoot) { if (String.IsNullOrEmpty(prefix)) { if (String.IsNullOrEmpty(ns)) { writer.WriteStartElement(markupObj.ObjectType.Name, NamespaceCache.DefaultNamespace); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, NamespaceCache.DefaultNamespace); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); writer.WriteAttributeString("xmlns", NamespaceCache.XmlnsNamespace, ns); } } else { if (doc.LocalName == markupObj.ObjectType.Name) { if (doc.NamespaceURI == ns) { if (doc.Prefix == prefix) { } } } } //writer.WriteAttributeString("xmlns", "x", // NamespaceCache.XmlnsNamespace, NamespaceCache.XamlNamespace); //foreach (NamespaceMap map in _dicNamespaceMap.Values) { // if (!String.IsNullOrEmpty(map.Prefix) && !String.Equals(map.Prefix, "x")) // writer.WriteAttributeString("xmlns", map.Prefix, NamespaceCache.XmlnsNamespace, map.XmlNamespace); //} } else { //TODO: Fix - the best way to handle this case... if (markupObj.ObjectType.Name == "PathFigureCollection" && markupObj.Instance != null) { WriteState writeState = writer.WriteState; if (writeState == WriteState.Element) { writer.WriteAttributeString("Figures", markupObj.Instance.ToString()); } else { if (String.IsNullOrEmpty(prefix)) { writer.WriteStartElement("PathGeometry.Figures"); } else { writer.WriteStartElement("PathGeometry.Figures", ns); } writer.WriteString(markupObj.Instance.ToString()); writer.WriteEndElement(); } return; } else { if (String.IsNullOrEmpty(prefix)) { writer.WriteStartElement(markupObj.ObjectType.Name); } else { writer.WriteStartElement(markupObj.ObjectType.Name, ns); } } } // Add the x:Name for object like Geometry/Drawing not derived from FrameworkElement... DependencyObject dep = obj as DependencyObject; if (dep != null) { string nameValue = dep.GetValue(FrameworkElement.NameProperty) as string; if (!String.IsNullOrEmpty(nameValue) && !(dep is FrameworkElement)) { writer.WriteAttributeString("x", "Name", NamespaceCache.XamlNamespace, nameValue); } } if (key != null) { string keyString = key.ToString(); if (keyString.Length > 0) { writer.WriteAttributeString("x", "Key", NamespaceCache.XamlNamespace, keyString); } else { //TODO: key may not be a string, what about x:Type... throw new NotImplementedException( "Sample XamlWriter cannot yet handle keys that aren't strings"); } } //Look for CPA info in our cache that keeps contentProperty names per Type //If it doesn't have an entry, go get the info and store it. if (!_contentProperties.ContainsKey(objectType)) { string lookedUpContentProperty = String.Empty; foreach (Attribute attr in markupObj.Attributes) { ContentPropertyAttribute cpa = attr as ContentPropertyAttribute; if (cpa != null) { lookedUpContentProperty = cpa.Name; //Once content property is found, come out of the loop. break; } } _contentProperties.Add(objectType, lookedUpContentProperty); } contentPropertyName = _contentProperties[objectType]; string contentString = String.Empty; foreach (MarkupProperty markupProperty in markupObj.Properties) { if (markupProperty.Name != contentPropertyName) { if (markupProperty.IsValueAsString) { contentString = markupProperty.Value as string; } else if (!markupProperty.IsComposite) { string temp = markupProperty.StringValue; if (markupProperty.IsAttached) { string ns1 = _namespaceCache.GetNamespaceUriFor(markupProperty.DependencyProperty.OwnerType); string prefix1 = _namespaceCache.GetDefaultPrefixFor(ns1); if (String.IsNullOrEmpty(prefix1)) { writer.WriteAttributeString(markupProperty.Name, temp); } else { writer.WriteAttributeString(markupProperty.Name, ns1, temp); } } else { if (markupProperty.Name == "FontUri" && (_wpfSettings != null)) { string fontUri = temp.ToLower(); fontUri = fontUri.Replace(_windowsDir, _windowsPath); StringBuilder builder = new StringBuilder(); builder.Append("{"); builder.Append("svg"); builder.Append(":"); builder.Append("SvgFontUri "); builder.Append(fontUri); builder.Append("}"); writer.WriteAttributeString(markupProperty.Name, builder.ToString()); } else { if (doc.HasAttribute(markupProperty.Name)) { PropertyInfo pI = obj.GetType().GetProperty(markupProperty.Name); SetValue(pI, doc, obj); } } } } else if (markupProperty.Value.GetType() == _nullType) { if (_nullExtension) { //writer.WriteAttributeString(markupProperty.Name, "{x:Null}"); } } else { propertyElements.Add(markupProperty); } } else { contentProperty = markupProperty; } } if (contentProperty != null || propertyElements.Count > 0 || contentString != String.Empty) { foreach (MarkupProperty markupProp in propertyElements) { string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name; if (doc.HasChildNodes) { foreach (XmlElement child in doc.ChildNodes) { if (child.LocalName == propElementName) { if (child.HasChildNodes) { foreach (XmlElement _child in child.ChildNodes) { string _namespace = _child.NamespaceURI; string _prefix = _child.Prefix; string _nameType = _namespace + "." + _child.LocalName; if (IsKnowType(_nameType)) { Type _type = Type.GetType(_nameType); object _obj = _type.InvokeMember(_type.FullName, BindingFlags.CreateInstance, null, null, null); Create(_type, _child, _obj); IList collection = markupProp.Value as IList; IDictionary dictionary = markupProp.Value as IDictionary; if (collection != null) { collection.Add(_obj); } } } } } } } } if (contentString != String.Empty) { //writer.WriteValue(contentString); } else if (contentProperty != null) { if (contentProperty.Value is string) { //writer.WriteValue(contentProperty.StringValue); } else { //WriteChildren(writer, contentProperty); } } } //writer.WriteEndElement(); }
protected DataRow GetInstanceRow(MarkupProperty mp) { string pId = mp.TupleParentList[0].Replace(":", "_"); return(GetInstanceRow(mp.elementId, pId, viewTables.Count - 1)); }