Exemple #1
0
        public static string StripNSPrefix(string str)
        {
            string prefix;
            string localName;

            XmlProperty.SplitLocalName(str, out prefix, out localName);

            if (string.IsNullOrEmpty(localName))
            {
                return(str);
            }

            return(localName);

            //if (str.Length < 2) return str;

            //int index = str.IndexOf(':');

            //if (index == -1) return str;

            //if (index == str.Length - 1) return string.Empty;

            //return str.Substring(index + 1);
        }
Exemple #2
0
        protected void GetXmlFragment_(XmlWriter xmlWriter, bool absoluteLinks)
        {
            if (HasXmlProperty)
            {
                string name = GetXmlElementPrefixedLocalName();
                string NSPrefix;
                string localName;
                XmlProperty.SplitLocalName(name, out NSPrefix, out localName);

                //DebugFix.Assert(string.IsNullOrEmpty(NSPrefix));

                string nsUri = GetXmlNamespaceUri(NSPrefix);

                XmlProperty xmlProp = GetXmlProperty();

                if (String.IsNullOrEmpty(NSPrefix))
                {
                    if (!String.IsNullOrEmpty(nsUri))
                    {
                        xmlWriter.WriteStartElement(name, nsUri);
                    }
                    else
                    {
#if DEBUG
                        Debugger.Break();
#endif //DEBUG
                        xmlWriter.WriteStartElement(name);
                    }
                }
                else
                {
                    //#if DEBUG
                    //                    Debugger.Break();
                    //#endif //DEBUG
                    if (!String.IsNullOrEmpty(nsUri))
                    {
                        xmlWriter.WriteStartElement(NSPrefix, localName, nsUri);
                    }
                    else
                    {
#if DEBUG
                        Debugger.Break();
#endif //DEBUG
                        xmlWriter.WriteStartElement(name);
                    }
                }

                ManagedImageMedia manImageMedia = GetImageMedia() as ManagedImageMedia;
                ManagedVideoMedia manVideoMedia = GetVideoMedia() as ManagedVideoMedia;

                foreach (XmlAttribute xmlAttr in xmlProp.Attributes.ContentsAs_Enumerable)
                {
                    string value = xmlAttr.Value;

                    string nsUriAttr = xmlAttr.GetNamespaceUri();

                    string attrNSPrefix      = xmlAttr.Prefix;
                    string nameWithoutPrefix = xmlAttr.PrefixedLocalName != null ? xmlAttr.PrefixedLocalName : xmlAttr.LocalName;

                    if (manImageMedia != null &&
                        (nameWithoutPrefix == "href" || nameWithoutPrefix == "src"))
                    {
                        DebugFix.Assert(manImageMedia.ImageMediaData.OriginalRelativePath == value);
                        if (absoluteLinks)
                        {
                            value = ((FileDataProvider)manImageMedia.ImageMediaData.DataProvider).DataFileFullPath;
                        }
                    }

                    if (manVideoMedia != null &&
                        (nameWithoutPrefix == "href" || nameWithoutPrefix == "src"))
                    {
                        DebugFix.Assert(manVideoMedia.VideoMediaData.OriginalRelativePath == value);
                        if (absoluteLinks)
                        {
                            value = ((FileDataProvider)manVideoMedia.VideoMediaData.DataProvider).DataFileFullPath;
                        }
                    }


                    if (String.IsNullOrEmpty(attrNSPrefix))
                    {
                        if (nameWithoutPrefix.Equals(XmlReaderWriterHelper.NS_PREFIX_XMLNS))
                        {
                            DebugFix.Assert(XmlReaderWriterHelper.NS_URL_XMLNS.Equals(nsUriAttr));

                            xmlWriter.WriteAttributeString(XmlReaderWriterHelper.NS_PREFIX_XMLNS, XmlReaderWriterHelper.NS_URL_XMLNS, value);
                        }
                        else if (!String.IsNullOrEmpty(nsUriAttr) && nsUriAttr != nsUri)
                        {
#if DEBUG
                            Debugger.Break();
#endif //DEBUG
                            xmlWriter.WriteAttributeString(nameWithoutPrefix, nsUriAttr, value);
                        }
                        else
                        {
                            xmlWriter.WriteAttributeString(nameWithoutPrefix, value);
                        }
                    }
                    else
                    {
                        if (attrNSPrefix.Equals(XmlReaderWriterHelper.NS_PREFIX_XMLNS))
                        {
                            DebugFix.Assert(nsUriAttr == XmlReaderWriterHelper.NS_URL_XMLNS);
                            xmlWriter.WriteAttributeString(XmlReaderWriterHelper.NS_PREFIX_XMLNS, nameWithoutPrefix, XmlReaderWriterHelper.NS_URL_XMLNS,
                                                           value);
                        }
                        else if (attrNSPrefix.Equals(XmlReaderWriterHelper.NS_PREFIX_XML))
                        {
                            DebugFix.Assert(nsUriAttr == XmlReaderWriterHelper.NS_URL_XML);
                            xmlWriter.WriteAttributeString(XmlReaderWriterHelper.NS_PREFIX_XML, nameWithoutPrefix, XmlReaderWriterHelper.NS_URL_XML,
                                                           value);
                        }
                        else if (!String.IsNullOrEmpty(nsUriAttr))
                        {
#if DEBUG
                            //DebugFix.Assert(nsUriAttr != nsUri);

                            string uriCheck = xmlProp.GetNamespaceUri(attrNSPrefix);
                            DebugFix.Assert(nsUriAttr == uriCheck);
#endif //DEBUG
                            xmlWriter.WriteAttributeString(attrNSPrefix, nameWithoutPrefix, nsUriAttr, value);
                        }
                        else if (!String.IsNullOrEmpty(nsUri))
                        {
#if DEBUG
                            Debugger.Break();
#endif //DEBUG
                            xmlWriter.WriteAttributeString(attrNSPrefix, nameWithoutPrefix, nsUri, value);
                        }
                        else
                        {
#if DEBUG
                            Debugger.Break();
#endif //DEBUG
                            xmlWriter.WriteAttributeString(nameWithoutPrefix, value);
                        }
                    }
                }
            }

            if (mChildren.Count > 0)
            {
                for (int i = 0; i < mChildren.Count; i++)
                {
                    TreeNode child = mChildren.Get(i);

                    child.GetXmlFragment_(xmlWriter, absoluteLinks);
                }
            }
            else
            {
                AbstractTextMedia txt = GetTextMedia();
                if (txt != null)
                {
                    DebugFix.Assert(!HasXmlProperty || mChildren.Count == 0);

                    bool     needsCData = false;
                    TreeNode node       = null;
                    if (HasXmlProperty)
                    {
                        node = this;
                    }
                    else if (Parent != null && Parent.HasXmlProperty)
                    {
                        node = Parent;
                    }
                    if (node != null)
                    {
                        string name = node.GetXmlElementLocalName();
                        if (name == "script" || name == "style")
                        {
                            needsCData = true;
                        }
                    }

                    if (needsCData)
                    {
                        xmlWriter.WriteCData(txt.Text);
                    }
                    else
                    {
                        xmlWriter.WriteString(txt.Text);
                    }
                }
            }

            if (HasXmlProperty)
            {
                xmlWriter.WriteEndElement();
            }
        }
        public static XmlAttribute CreateAppendXmlAttribute(XmlDocument xmlDoc, XmlNode node, string name, string val, string strNamespace)
        {
            XmlAttribute attr = null;

            string prefix;
            string localName;

            XmlProperty.SplitLocalName(name, out prefix, out localName);

            if (prefix != null)
            {
#if DEBUG
                string nsURI = node.GetNamespaceOfPrefix(prefix);
                DebugFix.Assert(strNamespace == nsURI);
#endif //DEBUG

                if (prefix == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                {
#if DEBUG
                    DebugFix.Assert(strNamespace == XmlReaderWriterHelper.NS_URL_XMLNS);
#endif //DEBUG

                    attr = xmlDoc.CreateAttribute(XmlReaderWriterHelper.NS_PREFIX_XMLNS, localName, XmlReaderWriterHelper.NS_URL_XMLNS);
                }
                else if (prefix == XmlReaderWriterHelper.NS_PREFIX_XML)
                {
#if DEBUG
                    DebugFix.Assert(strNamespace == XmlReaderWriterHelper.NS_URL_XML);
#endif //DEBUG

                    attr = xmlDoc.CreateAttribute(XmlReaderWriterHelper.NS_PREFIX_XML, localName, XmlReaderWriterHelper.NS_URL_XML);
                }
                else
                {
                    attr = xmlDoc.CreateAttribute(prefix, localName, strNamespace);
                }


                //XmlNode parentNode = xmlDoc.DocumentElement;

                //string parentAttributeName = XmlReaderWriterHelper.NS_PREFIX_XMLNS+":" + splitArray[0];

                //if (parentNode != null
                //    && parentNode.Attributes != null
                //    && parentNode.Attributes.GetNamedItem(parentAttributeName) != null
                //    && parentNode.Attributes.GetNamedItem(parentAttributeName).Value == strNamespace)
                //{
                //    //System.Console.WriteLine ( parentNode.Name );
                //    // do nothing
                //}
                //else if (parentNode != null)
                //{
                //    CreateAppendXmlAttribute(xmlDoc, parentNode, parentAttributeName, strNamespace);
                //}
                //attr = xmlDoc.CreateAttribute(name, "SYSTEM");
            }
            else
            {
                if (name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                {
#if DEBUG
                    DebugFix.Assert(strNamespace == XmlReaderWriterHelper.NS_URL_XMLNS);
#endif //DEBUG
                    attr = xmlDoc.CreateAttribute(name, strNamespace);
                }
                else
                {
//#if DEBUG
//                    DebugFix.Assert(strNamespace == node.NamespaceURI);
//#endif //DEBUG

                    if (strNamespace == node.NamespaceURI)
                    {
                        attr = xmlDoc.CreateAttribute(name);
                    }
                    else
                    {
                        attr = xmlDoc.CreateAttribute(name, strNamespace);
                    }
                }
            }

            attr.Value = val;
            node.Attributes.Append(attr);
            return(attr);
        }