Пример #1
0
      public static XPathItem ToXPathItem(this XdmItem value) {

         if (value == null) throw new ArgumentNullException("value");

         return (value.IsAtomic()) ? ToXPathItem((XdmAtomicValue)value)
            : ToXPathItem((XdmNode)value);
      }
Пример #2
0
 public override int runCommand(XdmNode node)
 {
     if (getProperties().ContainsKey("test"))
     {
         string  exp   = getProperties()["test"];
         XdmItem child = XMLContext.instance.xpath.EvaluateSingle(exp, node);
         if (child.IsAtomic() && child.Matches(XdmAtomicType.BOOLEAN))
         {
             if (((XdmAtomicValue)child).GetBooleanValue())
             {
                 runChilds(node);
             }
             return(0);
         }
         else
         {
             logger.log("Expression \"" + exp + "\" not a boolean!");
             return(-1);
         }
         //
     }
     else
     {
         logger.log("Check \"test\" parameter at If command!");
         return(-1);
     }
 }
Пример #3
0
            public override IXdmEnumerator Call(IXdmEnumerator[] arguments, DynamicContext context)
            {
                XdmNode node = arguments[0].AsNodes().Single();

                var options = new XPathSerializationOptions();

                XdmItem arg2 = null;

                if (arguments.Length > 1 &&
                    (arg2 = arguments[1].AsItems().SingleOrDefault()) != null)
                {
                    if (arg2.IsAtomic())
                    {
                        string methodLexical = arg2.ToString();

                        QName method = (context.ContextItem == null || context.ContextItem.IsAtomic()) ?
                                       new QName(methodLexical)
                     : new QName(methodLexical, (XdmNode)context.ContextItem);

                        options.Method = method.ToXmlQualifiedName();
                    }
                }

                Serializer serializer = this.itemFactory.CreateSerializer(options);

                if (arg2 != null &&
                    !arg2.IsAtomic())
                {
                    foreach (XdmNode attr in ((IXdmEnumerator)((XdmNode)arg2).EnumerateAxis(XdmAxis.Attribute)).AsNodes())
                    {
                        serializer.SetOutputProperty(attr.NodeName, attr.StringValue);
                    }
                }

                using (var writer = new StringWriter()) {
                    serializer.SetOutputWriter(writer);

                    this.itemFactory.processor.WriteXdmValue(node, serializer);

                    return(writer.ToString().ToXdmAtomicValue().GetXdmEnumerator());
                }
            }
Пример #4
0
        public override XPathItem CreateAtomicValue(object value, XmlQualifiedName qualifiedName)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            if (qualifiedName == null)
            {
                throw new ArgumentNullException("qualifiedName");
            }

            XdmAtomicValue atomicValue;
            XdmValue       xdmValue = value.ToXdmValue(this);

            if (xdmValue.Count != 1)
            {
                throw new ArgumentException("value cannot be empty, or more than one item.", "value");
            }

            try {
                XdmItem item = xdmValue.GetXdmEnumerator().AsItems().Single();

                if (item.IsAtomic())
                {
                    atomicValue = (XdmAtomicValue)item;

                    if (!qualifiedName.IsEmpty)
                    {
                        XmlQualifiedName typeName = atomicValue.GetTypeName(this.processor).ToXmlQualifiedName();

                        if (typeName != qualifiedName)
                        {
                            atomicValue = new XdmAtomicValue(value.ToString(), new QName(qualifiedName), this.processor);
                        }
                    }
                }
                else
                {
                    atomicValue = (!qualifiedName.IsEmpty) ?
                                  new XdmAtomicValue(value.ToString(), new QName(qualifiedName), this.processor)
                  : new XdmAtomicValue(value.ToString());
                }
            } catch (Exception ex) {
                throw new SaxonException(ex.Message, ex);
            }

            return(atomicValue.ToXPathItem());
        }