//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ private void GetSchemaElementFromSchema() { thisSchema = thisParentFragment.Schemas.GetSchemaFromTargetNamespace(this.Namespace, thisParentFragment); if (thisSchema == null) { if (thisParentFragment.Schemas.Count == 0) { string MessageFormat = AssemblyResources.GetName("NoSchemasForFragment"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat); thisParentFragment.AddValidationError(new ItemValidationError(this, MessageFormatBuilder.ToString())); } else { string MessageFormat = AssemblyResources.GetName("NoSchemasForNamespace"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat, this.Name, this.Namespace); thisParentFragment.AddValidationError(new ItemValidationError(this, MessageFormatBuilder.ToString())); } } this.SchemaElement = thisParentFragment.Schemas.GetElement(this.Name); if (this.SchemaElement == null) { string MessageFormat = AssemblyResources.GetName("CannotFindFactElementInSchema"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat, this.Name, thisSchema.SchemaReferencePath); thisParentFragment.AddValidationError(new ItemValidationError(this, MessageFormatBuilder.ToString())); } }
private void ValidateScenarioNode(INode ScenarioNode) { if (ScenarioNode.NamespaceURI.Equals(XbrlDocument.XbrlNamespaceUri) == true) { string MessageFormat = AssemblyResources.GetName("ScenarioNodeUsingXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, this.Id, ScenarioNode.Name); this.Fragment.AddValidationError(new ContextValidationError(this, MessageBuilder.ToString())); } if (ScenarioNode.Prefix.Length > 0) { XbrlSchema NodeSchema = this.Fragment.GetXbrlSchemaForPrefix(ScenarioNode.Prefix); if (NodeSchema != null) { Element NodeElement = NodeSchema.GetElement(ScenarioNode.LocalName); if (NodeElement != null) { if (NodeElement.SubstitutionGroup != Element.ElementSubstitutionGroup.Unknown) { string MessageFormat = AssemblyResources.GetName("ScenarioNodeUsingSubGroupInXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, this.Id, ScenarioNode.Name, NodeSchema.Path); this.Fragment.AddValidationError(new ContextValidationError(this, MessageBuilder.ToString())); } } } } foreach (INode CurrentChild in ScenarioNode.ChildNodes) { ValidateScenarioNode(CurrentChild); } }
/// <summary> /// Returns the label stored in a label linkbase for a given locator. /// </summary> /// <param name="schema"> /// The compiled schema which whose elements should be searched. /// </param> /// <param name="labelLocator"> /// The locator of the label to be returned. /// </param> /// <param name="labelLink"> /// The link label to be searched. /// </param> /// <returns> /// The label for the given locator, or an empty string if there is no /// label. /// </returns> private string GetLabel(XbrlSchema schema, Locator labelLocator, LabelLink labelLink) { var labelLinkbase = schema.LabelLinkbase; if (labelLinkbase == null) { return(string.Empty); } // Find label locator with href matching labelLocator.Href // Find label arc with from matching label locator.Label // find label with label matching label arc.To // grab innerText ... GET HYPE var labelLinkLocator = labelLink.GetLocator(labelLocator.Href); if (labelLinkLocator == null) { return(string.Empty); } var labelArc = labelLink.GetLabelArc(labelLinkLocator.Label); if (labelArc == null) { return(string.Empty); } var finalLabel = labelLink.GetLabel(labelArc.ToId); if (finalLabel == null) { return(string.Empty); } return(finalLabel.Text); }
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ private void GetSchemaElementFromSchema() { foreach (XbrlSchema CurrentSchema in thisParentFragment.Schemas) { if (CurrentSchema.TargetNamespace == this.Namespace) { thisSchema = CurrentSchema; } } if (thisSchema == null) { if (thisParentFragment.Schemas.Count == 0) { string MessageFormat = AssemblyResources.GetName("NoSchemasForFragment"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat); thisParentFragment.AddValidationError(new ItemValidationError(this, MessageFormatBuilder.ToString())); } thisSchema = thisParentFragment.Schemas[0]; } this.SchemaElement = thisSchema.GetElement(this.Name); if (this.SchemaElement == null) { string MessageFormat = AssemblyResources.GetName("CannotFindFactElementInSchema"); StringBuilder MessageFormatBuilder = new StringBuilder(); MessageFormatBuilder.AppendFormat(MessageFormat, this.Name, thisSchema.Path); thisParentFragment.AddValidationError(new ItemValidationError(this, MessageFormatBuilder.ToString())); } }
private void ProcessSchemaNamespaceAndLocation(string schemaNamespace, string schemaLocation) { var newSchema = new XbrlSchema(this, schemaLocation, string.Empty); if (newSchema.SchemaRootNode != null) { AddSchemaToSchemaList(newSchema); } }
//------------------------------------------------------------------------------- //------------------------------------------------------------------------------- private void ReadTaxonomySchemaReference(INode SchemaRefNode) { string HrefAttributeValue = SchemaRefNode.GetAttributeValue(Xlink.XlinkNode.xlinkNamespace, "href"); string Base = SchemaRefNode.GetAttributeValue(XbrlDocument.XmlNamespaceUri, "base"); var newSchema = new XbrlSchema(this, HrefAttributeValue, Base); if (newSchema.SchemaRootNode != null) { AddSchemaToSchemaList(newSchema); } }
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ internal LinkbaseDocument(XbrlSchema ContainingXbrlSchema, string DocumentPath) { this.Schema = ContainingXbrlSchema; thisLinkbasePath = GetFullLinkbasePath(DocumentPath); thisXmlDocument = Container.Resolve <IDocument>(); thisXmlDocument.Load(thisLinkbasePath); thisNamespaceManager = Container.Resolve <INamespaceManager>(); thisNamespaceManager.Document = thisXmlDocument; thisNamespaceManager.AddNamespace("default", XbrlDocument.XbrlLinkbaseNamespaceUri); thisLinkbaseNode = thisXmlDocument.SelectSingleNode("//default:linkbase", thisNamespaceManager); }
internal PresentationLinkbaseDocument(XbrlSchema ContainingXbrlSchema, string DocumentPath) : base(ContainingXbrlSchema, DocumentPath) { PresentationLinks = new List <PresentationLink>(); foreach (INode CurrentChild in thisLinkbaseNode.ChildNodes) { if (CurrentChild.LocalName.Equals("presentationLink") == true) { this.PresentationLinks.Add(new PresentationLink(CurrentChild)); } } }
/// <summary> /// Validates all summation concepts defined in the current schema. /// </summary> /// <param name="CurrentSchema"> /// The schema whose containing summation concepts should be validated. /// </param> private void Validate(XbrlSchema CurrentSchema) { var calculationLinkbase = CurrentSchema.CalculationLinkbase; if (calculationLinkbase == null) { return; } foreach (CalculationLink CurrentCalculationLink in calculationLinkbase.CalculationLinks) { Validate(CurrentCalculationLink); } }
internal PresentableFactTree(XbrlSchema schema, FactCollection facts) { TopLevelNodes = new List <PresentableFactTreeNode>(); var presentationLinkbase = schema.PresentationLinkbase; foreach (var presentationLink in presentationLinkbase.PresentationLinks) { var unorderedPresentationArcs = presentationLink.PresentationArcs; var orderedPresentationArcs = unorderedPresentationArcs.OrderBy(o => o.Order).ToList(); var newTreeNode = new PresentableFactTreeNode(); TopLevelNodes.Add(newTreeNode); foreach (var orderedPresentationArc in orderedPresentationArcs) { // Set the tree node's node fact, if it is not already set. // // This code is making an assumption that each arc in the link is set up with // the same "from" locator, so locating the "from" fact only needs to be done // if it is not already set. If it is already set, the code assumes that it // was set from a previous arc and doesn't not need to be set again (presumably // with the same information it would get this time if it did all of the work // again). // // If the locator references an abstract element, then there will be no fact // and the value will remain null. if (newTreeNode.NodeFact == null) { var fromLocator = GetLocator(orderedPresentationArc.From, presentationLink); newTreeNode.PresentationLinkbaseLocator = fromLocator; newTreeNode.NodeLabel = GetLabel(schema, fromLocator); var fromElement = GetElement(schema, fromLocator.HrefResourceId); if (fromElement.IsAbstract == false) { var fromFact = facts.GetFactByName(fromElement.Name); newTreeNode.NodeFact = fromFact; } } var toLocator = GetLocator(orderedPresentationArc.To, presentationLink); var newChildTreeNode = new PresentableFactTreeNode(); newTreeNode.ChildNodes.Add(newChildTreeNode); newTreeNode.NodeLabel = GetLabel(schema, toLocator); newChildTreeNode.PresentationLinkbaseLocator = toLocator; var toElement = GetElement(schema, toLocator.HrefResourceId); if (toElement.IsAbstract == false) { var toFact = facts.GetFactByName(toElement.Name); newChildTreeNode.NodeFact = toFact; } } } }
/// <summary> /// Finds an element in the given schema with the given ID. /// </summary> /// <param name="schema"> /// The compiled schema which whose elements should be searched. /// </param> /// <param name="id"> /// The ID of the element to return. /// </param> /// <returns> /// The element whose ID matches the given ID, or null if no element can be found. /// </returns> private Element GetElement(XbrlSchema schema, string id) { foreach (var candidateElement in schema.Elements) { if (string.IsNullOrEmpty(candidateElement.Id) == false) { if (candidateElement.Id.Equals(id) == true) { return(candidateElement); } } } return(null); }
/// <summary> /// Adds a schema to the schema collection. /// </summary> /// <remarks> /// The supplied schema will not be added if its target namespace is already in the list. This will help /// with some of the XBRL instance documents in the XBRL Conformance Suite which uses both the "schemaLocation" /// attribute as well as a "schemaRef" node to specify the same schema. The "301-01-IdScopeValid.xml" /// instance document in the XBRL-CONF-CR5-2012-01-24 suite is one such example. /// </remarks> /// <param name="schemaToAdd"> /// The schema to be added. /// </param> internal void Add(XbrlSchema schemaToAdd) { var targetNamespaceAlreadyInList = false; foreach (var currentSchema in SchemaList) { if (schemaToAdd.TargetNamespace.Equals(currentSchema.TargetNamespace) == true) { targetNamespaceAlreadyInList = true; } } if (targetNamespaceAlreadyInList == false) { SchemaList.Add(schemaToAdd); } }
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ internal RoleType(XbrlSchema ContainingXbrlSchema, INode roleTypeNode) { this.Schema = ContainingXbrlSchema; this.UsedOnReferences = new List <string>(); this.RoleUri = new Uri(roleTypeNode.GetAttributeValue("roleURI")); this.Id = roleTypeNode.GetAttributeValue("id"); foreach (INode currentChild in roleTypeNode.ChildNodes) { if (currentChild.LocalName.Equals("definition") == true) { this.Definition = currentChild.InnerText; } if (currentChild.LocalName.Equals("usedOn") == true) { this.UsedOnReferences.Add(currentChild.InnerText); } } }
/// <summary> /// Returns the label stored in a label linkbase for a given locator. /// </summary> /// <param name="schema"> /// The compiled schema which whose elements should be searched. /// </param> /// <param name="labelLocator"> /// The locator of the label to be returned. /// </param> /// <returns> /// The label for the given locator, or an empty string if there is no /// label. /// </returns> private string GetLabel(XbrlSchema schema, Locator labelLocator) { var labelLinkbase = schema.LabelLinkbase; if (labelLinkbase == null) { return(string.Empty); } foreach (var labelLink in labelLinkbase.LabelLinks) { var foundLabel = GetLabel(schema, labelLocator, labelLink); if (string.IsNullOrEmpty(foundLabel) == false) { return(foundLabel); } } return(string.Empty); }
private static void ProcessSchemaNamespaceAndLocation(string schemaNamespace, string schemaLocation, XbrlFragment containingFragment) { foreach (var currentSchema in containingFragment.Schemas) { if (currentSchema.TargetNamespace.Equals(schemaNamespace) == true) { return; } if (currentSchema.TargetNamespaceAlias.Equals(schemaNamespace) == true) { return; } } var newSchema = new XbrlSchema(containingFragment, schemaLocation, string.Empty); if (newSchema.SchemaRootNode != null) { containingFragment.Schemas.Add(newSchema); } }
private void ValidateSegmentNodePrefix(INode SegmentNode) { if (SegmentNode.Prefix.Length > 0) { XbrlSchema NodeSchema = this.Fragment.GetXbrlSchemaForPrefix(SegmentNode.Prefix); if (NodeSchema != null) { Element NodeElement = NodeSchema.GetElement(SegmentNode.LocalName); if (NodeElement != null) { if (NodeElement.SubstitutionGroup != Element.ElementSubstitutionGroup.Unknown) { string MessageFormat = AssemblyResources.GetName("SegmentNodeUsingSubGroupInXBRLNamespace"); StringBuilder MessageBuilder = new StringBuilder(); MessageBuilder.AppendFormat(MessageFormat, this.Id, SegmentNode.Name, NodeSchema.Path); this.Fragment.AddValidationError(new ContextValidationError(this, MessageBuilder.ToString())); } } } } }
/// <summary> /// Class constructor. This constructor will store a message and an exception. /// </summary> /// <param name="schema"> /// The schema containing the error being reported. /// </param> /// <param name="message"> /// The message to be stored in the validation error. /// </param> /// <param name="exception"> /// The exception to be stored in the validation error. /// </param> internal SchemaValidationError(XbrlSchema schema, string message, Exception exception) : base(message, exception) { this.Schema = schema; }
/// <summary> /// Class constructor. This constructor will store a message and will automatically set the /// Exception property to a null value. /// </summary> /// <param name="schema"> /// The schema containing the error being reported. /// </param> /// <param name="message"> /// The message to be stored in the validation error. /// </param> internal SchemaValidationError(XbrlSchema schema, string message) : base(message) { this.Schema = schema; }
/// <summary> /// Adds a schema to the schema collection. /// </summary> /// <remarks> /// The supplied schema will not be added if its target namespace is already in the list. This will help /// with some of the XBRL instance documents in the XBRL Conformance Suite which uses both the "schemaLocation" /// attribute as well as a "schemaRef" node to specify the same schema. The "301-01-IdScopeValid.xml" /// instance document in the XBRL-CONF-CR5-2012-01-24 suite is one such example. /// </remarks> /// <param name="schemaToAdd"> /// The schema to be added. /// </param> private void AddSchemaToSchemaList(XbrlSchema schemaToAdd) { this.Schemas.Add(schemaToAdd); }