BExIS.Xml.Helpers.Mapping.XmlMapperManager.Generate C# (CSharp) Method

Generate() public method

public Generate ( XmlDocument metadataXml, long id, bool addEmptyNode = false ) : XmlDocument
metadataXml System.Xml.XmlDocument
id long
addEmptyNode bool
return System.Xml.XmlDocument
        public XmlDocument Generate(XmlDocument metadataXml, long id,bool addEmptyNode = false)
        {
            addAlsoEmptyNode = addEmptyNode;

            #region abcd (metadata from bexis to abcd)

            XmlDocument newMetadata = new XmlDocument();
            XmlDeclaration declaration = newMetadata.CreateXmlDeclaration("1.0", "utf-8", null);
            newMetadata.AppendChild(declaration);

            newMetadata.AppendChild(newMetadata.CreateElement(xmlMapper.Header.Destination.Prefix, xmlMapper.Header.Destination.XPath, xmlMapper.Header.Destination.NamepsaceURI));
            XmlNode root = newMetadata.DocumentElement;

            XmlAttribute rootAttr = newMetadata.CreateAttribute("xmlns");
            rootAttr.Value = xmlSchemaManager.Schema.TargetNamespace;
            root.Attributes.Append(rootAttr);

            // create nodes
            newMetadata = mapNode(newMetadata, newMetadata.DocumentElement, metadataXml.DocumentElement);

            // add required attributes
            newMetadata = addAttributes(newMetadata, newMetadata.DocumentElement);

            //add root attributes
            foreach (KeyValuePair<string, string> attribute in xmlMapper.Header.Attributes)
            {
                XmlAttribute attr = newMetadata.CreateAttribute(attribute.Key);
                attr.Value = attribute.Value;
                root.Attributes.Append(attr);
            }

            //add root namespaces
            foreach (KeyValuePair<string, string> package in xmlMapper.Header.Packages)
            {
                XmlAttribute attr = newMetadata.CreateAttribute(package.Key);
                attr.Value = package.Value;
                root.Attributes.Append(attr);
            }

            string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), "Metadata " + id + ".xml");

            newMetadata.Save(path);

            // the following call to Validate succeeds.
            //document.Validate(eventHandler);

            #endregion

            return newMetadata;
        }

Usage Example

Example #1
0
        public XmlDocument createMetadata(string dataSetID, string filePath, string DataBase, ref List<string> variableNames, ref string fileType)
        {
            string path_mappingFile = filePath + @"\bexis_metadata_mapping.xml";

            // query Bexis1 metadata from DB
            XmlDocument metadataBexis1 = getMetadataXml(dataSetID, DataBase);

            // Get variable names
            XmlNamespaceManager xnm = new XmlNamespaceManager(metadataBexis1.NameTable);
            xnm.AddNamespace("bgc", "http://www.bgc-jena.mpg.de");
            XmlNodeList variables = metadataBexis1.SelectNodes("bgc:metaProfile/bgc:data/bgc:dataStructure/bgc:variables/bgc:variable/bgc:name", xnm);
            foreach (XmlNode variable in variables)
            {
                variableNames.Add(variable.InnerText);
            }

            // is this data structure structured?
            XmlNode dataFileType = metadataBexis1.SelectSingleNode("bgc:metaProfile/bgc:data/bgc:fileType", xnm);
            fileType = dataFileType.InnerText;

            // XML mapper + mapping file
            XmlMapperManager xmlMapperManager = new XmlMapperManager();
            xmlMapperManager.Load(path_mappingFile, "BExIS");

            // generate Bpp metadata
            XmlDocument metadataBpp = xmlMapperManager.Generate(metadataBexis1, 99);

            return metadataBpp;
        }
All Usage Examples Of BExIS.Xml.Helpers.Mapping.XmlMapperManager::Generate