Exemple #1
0
        public void StartElement(string localName, string qName, SortedList <string, string> atts)
        {
            string type          = localName;
            string namespaceName = string.Empty;

            if (qName.Contains(StringManipulationManager.SeparatorColon))
            {
                namespaceName = qName.Substring(0, qName.IndexOf(StringManipulationManager.SeparatorColon));
            }

            if (string.Compare(qName, rdfRootQ, true) == 0)
            {
                //// rdf:RDF element - extract attributes
                if ((atts != null) && (atts.Count > 0))
                {
                    for (int i = 0; i < atts.Count; i++)
                    {
                        model.AddRDFAttribute(atts.ElementAt(i).Key, atts.ElementAt(i).Value);
                    }
                }
            }

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                //// start of new main element
                if (currentElement == null)
                {
                    inLevel        = Level.Element;
                    currentElement = new CIMObject(model.ModelContext, type);
                    string id = TryReadRDFIdAttribute(atts);
                    if (id != null)
                    {
                        currentElement.ID = id;
                    }
                    currentElement.CIMType         = type;
                    currentElement.NamespaceString = namespaceName;
                }
                //// new attribute
                else
                {
                    inLevel          = Level.Property;
                    currentAttribute = new ObjectAttribute(model.ModelContext, type);

                    currentAttribute.FullName        = type;
                    currentAttribute.NamespaceString = namespaceName;

                    ReadAndProcessAttributeValue(currentAttribute, atts);
                }
            }
        }
Exemple #2
0
        public override void StartElement(string localName, string qName, SortedList <string, string> attributes, int lineNumber = 0, int columnNumber = 0)
        {
            string type          = localName;
            string namespaceName = string.Empty;

            if (qName.Contains(StringManipulationManager.SeparatorColon))
            {
                namespaceName = qName.Substring(0, qName.IndexOf(StringManipulationManager.SeparatorColon));
            }

            if (string.Compare(qName, rdfRootQ, true) == 0)
            {
                //// rdf:RDF element - extract attributes
                if ((attributes != null) && (attributes.Count > 0))
                {
                    foreach (string attrName in attributes.Keys)
                    {
                        if (!attrName.StartsWith(xmlnsPrefix, true, null))
                        {
                            model.AddRDFAttribute(attrName, attributes[attrName]);
                        }
                    }
                }
            }

            if (string.Compare(rdfRoot, type, true) != 0)
            {
                string id = TryReadRDFIdAttribute(attributes);
                //// start of new main element
                if (currentElement == null)
                {
                    if (id != null)
                    {
                        inLevel           = Level.Element;
                        currentElement    = new CIMObject(model.ModelContext, type);
                        currentElement.ID = id;
                        currentElement.NamespaceString   = namespaceName;
                        currentElement.SourceStartLine   = lineNumber;
                        currentElement.SourceStartColumn = columnNumber;
                    }
                }
                //// start of new subelement (attribute or embedded element)
                else
                {
                    //// if rdf:ID is defined -> it is new embedded element
                    if (id != null)
                    {
                        inLevel            = Level.EmbeddedElement;
                        embeddedElement    = new CIMObject(model.ModelContext, type);
                        embeddedElement.ID = id;
                        embeddedElement.NamespaceString     = namespaceName;
                        embeddedElement.SourceStartLine     = lineNumber;
                        embeddedElement.SourceStartColumn   = columnNumber;
                        embeddedElement.IsDefinedAsEmbedded = true;

                        if (string.IsNullOrEmpty(embeddedListName))
                        {
                            embeddedListName = currentAttribute.FullName;
                            if (!string.IsNullOrEmpty(currentAttribute.NamespaceString))
                            {
                                embeddedListName = currentAttribute.NamespacePrintString + embeddedListName;
                            }
                        }
                        currentAttribute = null;
                        AddEmbeddedChildToCurrentElement();
                    }
                    //// new attribute
                    else
                    {
                        inLevel          = Level.Property;
                        currentAttribute = new ObjectAttribute(model.ModelContext, type);
                        currentAttribute.NamespaceString = namespaceName;

                        ReadAndProcessAttributeValue(currentAttribute, attributes);
                    }
                }
            }
        }