RtfNavigators store Xslt result-tree-fragments. At runtime, the Xslt library tests to see if a Navigator is an RtfNavigator in order to enforce certain restrictions, such as prohibiting querying into Rtfs. Furthermore, Rtfs must store extra serialization information required in order to properly implement the Xslt disable-output-escaping flag.
Inheritance: System.Xml.XPath.XPathNavigator
Ejemplo n.º 1
0
        public static string OuterXml(XPathNavigator navigator)
        {
            RtfNavigator rtf = navigator as RtfNavigator;

            if (rtf == null)
            {
                return(navigator.OuterXml);
            }
            StringBuilder     sb       = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            settings.ConformanceLevel   = ConformanceLevel.Fragment;
            settings.CheckCharacters    = false;
            XmlWriter xw = XmlWriter.Create(sb, settings);

            rtf.CopyToWriter(xw);
            xw.Close();
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an XmlQueryType that represents the type of "item".
        /// </summary>
        private XmlQueryType CreateXmlType(XPathItem item)
        {
            if (item.IsNode)
            {
                // Rtf
                RtfNavigator rtf = item as RtfNavigator;
                if (rtf != null)
                {
                    return(XmlQueryTypeFactory.Node);
                }

                // Node
                XPathNavigator nav = (XPathNavigator)item;
                switch (nav.NodeType)
                {
                case XPathNodeType.Root:
                case XPathNodeType.Element:
                    if (nav.XmlType == null)
                    {
                        return(XmlQueryTypeFactory.Type(nav.NodeType, XmlQualifiedNameTest.New(nav.LocalName, nav.NamespaceURI), XmlSchemaComplexType.UntypedAnyType, false));
                    }

                    return(XmlQueryTypeFactory.Type(nav.NodeType, XmlQualifiedNameTest.New(nav.LocalName, nav.NamespaceURI), nav.XmlType, nav.SchemaInfo.SchemaElement.IsNillable));

                case XPathNodeType.Attribute:
                    if (nav.XmlType == null)
                    {
                        return(XmlQueryTypeFactory.Type(nav.NodeType, XmlQualifiedNameTest.New(nav.LocalName, nav.NamespaceURI), DatatypeImplementation.UntypedAtomicType, false));
                    }

                    return(XmlQueryTypeFactory.Type(nav.NodeType, XmlQualifiedNameTest.New(nav.LocalName, nav.NamespaceURI), nav.XmlType, false));
                }

                return(XmlQueryTypeFactory.Type(nav.NodeType, XmlQualifiedNameTest.Wildcard, XmlSchemaComplexType.AnyType, false));
            }

            // Atomic value
            return(XmlQueryTypeFactory.Type((XmlSchemaSimpleType)item.XmlType, true));
        }
Ejemplo n.º 3
0
        public static XPathNavigator ToNode(XPathItem item)
        {
            XsltLibrary.CheckXsltValue(item);

            if (!item.IsNode)
            {
                // Create Navigator over text node containing string value of item
                XPathDocument doc    = new XPathDocument();
                XmlRawWriter  writer = doc.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames, string.Empty);
                writer.WriteString(ToString(item));
                writer.Close();
                return(doc.CreateNavigator());
            }

            RtfNavigator rtf = item as RtfNavigator;

            if (rtf != null)
            {
                return(rtf.ToNavigator());
            }

            return((XPathNavigator)item);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Convert from the Clr type of "value" to Clr type "destinationType" using V1 Xslt rules.
        /// These rules include converting any Rtf values to Nodes.
        /// </summary>
        internal object ChangeTypeXsltArgument(XmlQueryType xmlType, object value, Type destinationType)
        {
#if FEATURE_COMPILED_XSL
            Debug.Assert(XmlILTypeHelper.GetStorageType(xmlType).IsAssignableFrom(value.GetType()),
                         "Values passed to ChangeTypeXsltArgument should be in ILGen's default Clr representation.");
#endif
            Debug.Assert(destinationType == XsltConvert.ObjectType || !destinationType.IsAssignableFrom(value.GetType()),
                         "No need to call ChangeTypeXsltArgument since value is already assignable to destinationType " + destinationType);

            switch (xmlType.TypeCode)
            {
            case XmlTypeCode.String:
                if (destinationType == XsltConvert.DateTimeType)
                {
                    value = XsltConvert.ToDateTime((string)value);
                }
                break;

            case XmlTypeCode.Double:
                if (destinationType != XsltConvert.DoubleType)
                {
                    value = Convert.ChangeType(value, destinationType, CultureInfo.InvariantCulture);
                }
                break;

            case XmlTypeCode.Node:
                Debug.Assert(xmlType != XmlQueryTypeFactory.Node && xmlType != XmlQueryTypeFactory.NodeS,
                             "Rtf values should have been eliminated by caller.");

                if (destinationType == XsltConvert.XPathNodeIteratorType)
                {
                    value = new XPathArrayIterator((IList)value);
                }
                else if (destinationType == XsltConvert.XPathNavigatorArrayType)
                {
                    // Copy sequence to XPathNavigator[]
                    IList <XPathNavigator> seq      = (IList <XPathNavigator>)value;
                    XPathNavigator[]       navArray = new XPathNavigator[seq.Count];

                    for (int i = 0; i < seq.Count; i++)
                    {
                        navArray[i] = seq[i];
                    }

                    value = navArray;
                }
                break;

            case XmlTypeCode.Item:
            {
                // Only typeof(object) is supported as a destination type
                if (destinationType != XsltConvert.ObjectType)
                {
                    throw new XslTransformException(SR.Xslt_UnsupportedClrType, destinationType.Name);
                }

                // Convert to default, backwards-compatible representation
                //   1. NodeSet: System.Xml.XPath.XPathNodeIterator
                //   2. Rtf: System.Xml.XPath.XPathNavigator
                //   3. Other:   Default V1 representation
                IList <XPathItem> seq = (IList <XPathItem>)value;
                if (seq.Count == 1)
                {
                    XPathItem item = seq[0];

                    if (item.IsNode)
                    {
                        // Node or Rtf
                        RtfNavigator rtf = item as RtfNavigator;
                        if (rtf != null)
                        {
                            value = rtf.ToNavigator();
                        }
                        else
                        {
                            value = new XPathArrayIterator((IList)value);
                        }
                    }
                    else
                    {
                        // Atomic value
                        value = item.TypedValue;
                    }
                }
                else
                {
                    // Nodeset
                    value = new XPathArrayIterator((IList)value);
                }
                break;
            }
            }

            Debug.Assert(destinationType.IsAssignableFrom(value.GetType()), "ChangeType from type " + value.GetType().Name + " to type " + destinationType.Name + " failed");
            return(value);
        }