示例#1
0
        private void parseOpfDcMetaData(XmlDocument opfXmlDoc)
        {
            //Presentation presentation = DTBooktoXukConversion.m_Project.GetPresentation(0);
            Presentation presentation = m_Project.GetPresentation(0);

            XmlNodeList listOfMetaDataRootNodes = opfXmlDoc.GetElementsByTagName("dc-metadata");

            if (listOfMetaDataRootNodes != null)
            {
                foreach (XmlNode mdNodeRoot in listOfMetaDataRootNodes)
                {
                    XmlNodeList listOfMetaDataNodes = mdNodeRoot.ChildNodes;
                    if (listOfMetaDataNodes != null)
                    {
                        foreach (XmlNode mdNode in listOfMetaDataNodes)
                        {
                            if (mdNode.NodeType == XmlNodeType.Element)
                            {
                                Metadata md = presentation.MetadataFactory.CreateMetadata();
                                md.Name    = mdNode.Name;
                                md.Content = mdNode.InnerText;
                                presentation.AddMetadata(md);
                            }
                        }
                    }
                }
            }
        }//parseOpfDcMetaData
示例#2
0
        private void parseNcx(string ncxPath)
        {
            //Presentation presentation = DTBooktoXukConversion.m_Project.GetPresentation(0);
            Presentation presentation = m_Project.GetPresentation(0);
            //XmlDocument ncxXmlDoc = DTBooktoXukConversion.readXmlDocument(ncxPath);
            XmlDocument ncxXmlDoc = readXmlDocument(ncxPath);


            XmlNodeList listOfHeadRootNodes = ncxXmlDoc.GetElementsByTagName("head");

            if (listOfHeadRootNodes != null)
            {
                foreach (XmlNode headNodeRoot in listOfHeadRootNodes)
                {
                    XmlNodeList listOfMetaNodes = headNodeRoot.ChildNodes;
                    if (listOfMetaNodes != null)
                    {
                        foreach (XmlNode metaNode in listOfMetaNodes)
                        {
                            if (metaNode.NodeType == XmlNodeType.Element &&
                                metaNode.Name == "meta")
                            {
                                XmlAttributeCollection attributeCol = metaNode.Attributes;

                                if (attributeCol != null)
                                {
                                    XmlNode attrName    = attributeCol.GetNamedItem("name");
                                    XmlNode attrContent = attributeCol.GetNamedItem("content");
                                    if (attrName != null && attrContent != null && !String.IsNullOrEmpty(attrName.Value) &&
                                        !String.IsNullOrEmpty(attrContent.Value))
                                    {
                                        Metadata md = presentation.MetadataFactory.CreateMetadata();
                                        md.Name    = attrName.Value;
                                        md.Content = attrContent.Value;
                                        presentation.AddMetadata(md);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        }//parseOpfDcMetaData

        private void parseOpfMetaData(XmlDocument opfXmlDoc)
        {
            //Presentation presentation = DTBooktoXukConversion.m_Project.GetPresentation(0);
            Presentation presentation = m_Project.GetPresentation(0);

            XmlNodeList listOfMetaDataRootNodes = opfXmlDoc.GetElementsByTagName("x-metadata");

            if (listOfMetaDataRootNodes != null)
            {
                foreach (XmlNode mdNodeRoot in listOfMetaDataRootNodes)
                {
                    XmlNodeList listOfMetaDataNodes = mdNodeRoot.ChildNodes;
                    if (listOfMetaDataNodes != null)
                    {
                        foreach (XmlNode mdNode in listOfMetaDataNodes)
                        {
                            if (mdNode.NodeType == XmlNodeType.Element && mdNode.Name == "meta")
                            {
                                XmlAttributeCollection mdAttributes = mdNode.Attributes;

                                if (mdAttributes != null)
                                {
                                    XmlNode attrName    = mdAttributes.GetNamedItem("name");
                                    XmlNode attrContent = mdAttributes.GetNamedItem("content");

                                    if (attrName != null && attrContent != null && !String.IsNullOrEmpty(attrName.Value) &&
                                        !String.IsNullOrEmpty(attrContent.Value))
                                    {
                                        Metadata md = presentation.MetadataFactory.CreateMetadata();
                                        md.Name    = attrName.Value;
                                        md.Content = attrContent.Value;
                                        presentation.AddMetadata(md);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }//parseOpfMetaData
示例#4
0
        private void parseDTBookXmlDocAndPopulateDataModel(XmlNode xmlNode, core.TreeNode parentTreeNode)
        {
            XmlNodeType xmlType = xmlNode.NodeType;

            switch (xmlType)
            {
            case XmlNodeType.Attribute:
            {
                System.Diagnostics.Debug.Fail("Calling this method with an XmlAttribute should never happen !!");
                break;
            }

            case XmlNodeType.Document:
            {
                parseDTBookXmlDocAndPopulateDataModel(((XmlDocument)xmlNode).DocumentElement, parentTreeNode);
                break;
            }

            case XmlNodeType.Element:
            {
                Presentation presentation = m_Project.GetPresentation(0);

                core.TreeNode treeNode = presentation.TreeNodeFactory.Create();

                if (parentTreeNode == null)
                {
                    presentation.RootNode = treeNode;
                    parentTreeNode        = presentation.RootNode;
                }
                else
                {
                    parentTreeNode.AppendChild(treeNode);
                }

                XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty();
                treeNode.AddProperty(xmlProp);
                xmlProp.LocalName = xmlNode.Name;
                if (xmlNode.ParentNode != null && xmlNode.ParentNode.NodeType == XmlNodeType.Document)
                {
                    presentation.PropertyFactory.DefaultXmlNamespaceUri = xmlNode.NamespaceURI;
                }

                if (xmlNode.NamespaceURI != presentation.PropertyFactory.DefaultXmlNamespaceUri)
                {
                    xmlProp.NamespaceUri = xmlNode.NamespaceURI;
                }

                XmlAttributeCollection attributeCol = xmlNode.Attributes;

                if (attributeCol != null)
                {
                    for (int i = 0; i < attributeCol.Count; i++)
                    {
                        XmlNode attr = attributeCol.Item(i);
                        if (attr.Name != "smilref")
                        {
                            xmlProp.SetAttribute(attr.Name, "", attr.Value);
                        }
                    }


                    if (xmlNode.Name == "meta")
                    {
                        XmlNode attrName    = attributeCol.GetNamedItem("name");
                        XmlNode attrContent = attributeCol.GetNamedItem("content");
                        if (attrName != null && attrContent != null && !String.IsNullOrEmpty(attrName.Value) &&
                            !String.IsNullOrEmpty(attrContent.Value))
                        {
                            Metadata md = presentation.MetadataFactory.CreateMetadata();
                            md.Name    = attrName.Value;
                            md.Content = attrContent.Value;
                            presentation.AddMetadata(md);
                        }
                    }
                }


                foreach (XmlNode childXmlNode in xmlNode.ChildNodes)
                {
                    parseDTBookXmlDocAndPopulateDataModel(childXmlNode, treeNode);
                }
                break;
            }

            case XmlNodeType.Text:
            {
                Presentation presentation = m_Project.GetPresentation(0);

                string    text      = xmlNode.Value;
                TextMedia textMedia = presentation.MediaFactory.CreateTextMedia();
                textMedia.Text = text;

                ChannelsProperty cProp = presentation.PropertyFactory.CreateChannelsProperty();
                cProp.SetMedia(m_textChannel, textMedia);

                int counter = 0;
                foreach (XmlNode childXmlNode in xmlNode.ParentNode.ChildNodes)
                {
                    XmlNodeType childXmlType = childXmlNode.NodeType;
                    if (childXmlType == XmlNodeType.Text || childXmlType == XmlNodeType.Element)
                    {
                        counter++;
                    }
                }
                if (counter == 1)
                {
                    parentTreeNode.AddProperty(cProp);
                }
                else
                {
                    core.TreeNode txtWrapperNode = presentation.TreeNodeFactory.Create();
                    txtWrapperNode.AddProperty(cProp);
                    parentTreeNode.AppendChild(txtWrapperNode);
                }

                break;
            }

            default:
            {
                return;
            }
            }
        }