Пример #1
0
        public Element FindChild(Path path)
        {
            Element element = this;

            foreach (Segment segment in path.Segments)
            {
                element = element.FindChild(segment.Name);
                if (element == null)
                {
                    break;
                }
            }
            return(element);
        }
Пример #2
0
        public string DiscriminatorXPath()
        {
            //Segment segment = Discriminator.Tail;
            Element       element = this;
            List <string> pieces  = new List <string>();

            foreach (Segment segment in Discriminator.Segments)
            {
                element = element.FindChild(segment.Name);

                if (element == null)
                {
                    return("false");
                    // if the fixed value element can't be found, give back an all discriminating xpath.
                }

                string s;
                if (segment != Discriminator.Tail)
                {
                    s = string.Format("{0}:{1}", element.NameSpacePrefix, element.Name);
                }
                else
                {
                    if (element.Representation == Representation.Element)
                    {
                        s = string.Format("{0}:{1}/@value='{2}'", element.NameSpacePrefix, element.Name, this.SliceValue);
                    }
                    else
                    {
                        s = string.Format("@{0}='{1}'", element.Name, this.SliceValue);
                    }
                }
                pieces.Add(s);
            }
            return(string.Join("/", pieces));
        }