Ejemplo n.º 1
0
        public static XmlNodeList GetXmlNodes(
            XmlNode node,
            string child_node_name,
            XmlNamespaceManager nsmgr)
        {
            IEnumerator enumerator = nsmgr.GetEnumerator();
            XmlNodeList xmlNodeList;
            string      xpath;

            for (xmlNodeList = node.SelectNodes(child_node_name, nsmgr); xmlNodeList.Count == 0 && enumerator.MoveNext(); xmlNodeList = node.SelectNodes(xpath, nsmgr))
            {
                string current = (string)enumerator.Current;
                xpath = !("" != current) ? child_node_name : current + ":" + child_node_name;
            }
            return(xmlNodeList);
        }
Ejemplo n.º 2
0
            private static void AddNamespaces(IDbCommand command, XmlNamespaceManager nsManager)
            {
                if (nsManager != null)
                {
                    IEnumerator nsEnumerator = nsManager.GetEnumerator();
                    int         nsIndex      = 1;

                    while (nsEnumerator.MoveNext())
                    {
                        string nsPrefix = nsEnumerator.Current as string;

                        // Should filter the standard XML namespace, otherwise can get "Attempt to redefine namespace prefix 'xmlns'" error.
                        if (String.Compare(nsPrefix, "xmlns", true, CultureInfo.CurrentCulture) != 0)
                        {
                            command.Parameters.Add(SqlParameterUtility.CreateParameter(String.Format(CultureInfo.CurrentCulture, SqlObjectResources.CommandParamTemplateNamespace, nsIndex), SqlDbType.VarChar, String.Format(CultureInfo.CurrentCulture, SqlObjectResources.CommandParamTemplateNamespaceValue, nsPrefix, nsManager.LookupNamespace(nsPrefix))));
                            nsIndex++;
                        }
                    }
                }
            }
Ejemplo n.º 3
0
        //<selector
        //  id = ID
        //  xpath = a subset of XPath expression, see below
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?)
        //</selector>
        internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h, string name)
        {
            XmlSchemaXPath path = new XmlSchemaXPath();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != name)
            {
                error(h, "Should not happen :1: XmlSchemaComplexContentRestriction.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            path.LineNumber   = reader.LineNumber;
            path.LinePosition = reader.LinePosition;
            path.SourceUri    = reader.BaseURI;

            XmlNamespaceManager currentMgr = XmlSchemaUtil.GetParserContext(reader.Reader).NamespaceManager;

            if (currentMgr != null)
            {
                path.nsmgr = new XmlNamespaceManager(reader.NameTable);
                IEnumerator e = currentMgr.GetEnumerator();
                while (e.MoveNext())
                {
                    string prefix = e.Current as string;
                    switch (prefix)
                    {
                    case "xml":
                    case "xmlns":
                        continue;

                    default:
                        path.nsmgr.AddNamespace(prefix, currentMgr.LookupNamespace(prefix, false));
                        break;
                    }
                }
            }

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    path.Id = reader.Value;
                }
                else if (reader.Name == "xpath")
                {
                    path.xpath = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for " + name, null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, path);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(path);
            }

            //  Content: (annotation?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != name)
                    {
                        error(h, "Should not happen :2: XmlSchemaXPath.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                          //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        path.Annotation = annotation;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(path);
        }