Exemplo n.º 1
0
 /// <summary>
 /// Resolves a namespace prefix in the current element's scope.
 /// </summary>
 /// <param name="prefix">The prefix whose namespace URI you want to resolve. To match the default namespace, pass an empty string.</param>
 /// <returns>
 /// The namespace URI to which the prefix maps or null if no matching prefix is found.
 /// </returns>
 public override string LookupNamespace(string prefix)
 {
     return(AmlReader.NamespaceFromPrefix(prefix));
 }
Exemplo n.º 2
0
 internal AmlNavigator(IReadOnlyResult result) : this(AmlReader.GetElement(result))
 {
 }
Exemplo n.º 3
0
        /// <summary>
        /// Write the node to the specified <see cref="XmlWriter"/>
        /// </summary>
        /// <param name="writer"><see cref="XmlWriter"/> to write the node to</param>
        /// <param name="settings">Settings controlling how the node is written</param>
        public void ToAml(XmlWriter writer, AmlWriterSettings settings)
        {
            var name   = Name;
            var prefix = Prefix;
            var i      = name.IndexOf(':');
            var attrs  = LinkedListOps.Enumerate(_lastAttr).OfType <IReadOnlyAttribute>().ToArray();

            if (string.IsNullOrEmpty(prefix) && i > 0)
            {
                prefix = name.Substring(0, i);
                name   = name.Substring(i + 1);
            }
            if (string.IsNullOrEmpty(prefix))
            {
                writer.WriteStartElement(name);
            }
            else
            {
                var ns = AmlReader.NamespaceFromPrefix(prefix);
                writer.WriteStartElement(prefix, name, ns);
            }

            foreach (var attr in attrs)
            {
                i = attr.Name.IndexOf(':');
                if (i > 0)
                {
                    var attributePrefix = attr.Name.Substring(0, i);
                    if (attributePrefix == "xmlns")
                    {
                        continue;
                    }
                    name = attr.Name.Substring(i + 1);
                    var ns = AmlReader.NamespaceFromPrefix(attributePrefix);
                    writer.WriteAttributeString(attributePrefix, name, ns, attr.Value);
                }
                else
                {
                    writer.WriteAttributeString(attr.Name, attr.Value);
                }
            }
            if (!(_content is ILinkedElement))
            {
                if (PreferCData)
                {
                    writer.WriteCData(this.Value);
                }
                else
                {
                    writer.WriteString(this.Value);
                }
            }
            else
            {
                var elems = Elements().ToArray();
                var item  = elems.OfType <IReadOnlyItem>().FirstOrDefault();
                if (this is IReadOnlyProperty &&
                    !settings.ExpandPropertyItems &&
                    item?.Attribute("action").Exists == false)
                {
                    writer.WriteAttributeString("type", item.TypeName());
                    var keyedName = item.KeyedName().Value ?? item.Property("id").KeyedName().Value;
                    if (!string.IsNullOrEmpty(keyedName))
                    {
                        writer.WriteAttributeString("keyed_name", keyedName);
                    }
                    writer.WriteString(item.Id());
                }
                else
                {
                    foreach (var e in elems)
                    {
                        e.ToAml(writer, settings);
                    }
                }
            }
            writer.WriteEndElement();
        }
Exemplo n.º 4
0
 internal AmlNavigator(ServerException ex) : this(AmlReader.GetElement(ex))
 {
 }