Select to view content in your preferred language

Help needed.. probably easy - adding a layer

766
4
11-18-2011 02:59 AM
JohnMorris3
Emerging Contributor
Folks,
I am sorry to bother you with such a trivial question but my coding inexperience is preventing me from understanding how to get data from an xml file ( http://www.weclickit.com/fingal/castlesandshit.xml for example ) and get it to show on the ESRI Standard Map Application project that I have started in VS10.  I am a 48 year old man, back in college.. what was I thinking???

I got the template loaded OK after a while and it looks great.  It is exactly what I need for my college project.  The project is all about deployment to Azure but must have functionality. 
I have five xml files for different subject matters in my area... schools, stately homes, recycle centres etc.

I would love to be able to use the menu in the template to show layers - see screenshot


I want to let you know that I am not taking your time and effort for granted folks, I have looked and read but it's a real struggle.  Whoever Helps me solve it, I will name my next child after them 😄 (I don't intend having any more children...)

Thanks so much in advance for any help folks.

Cheers

QTour, Ireland
0 Kudos
4 Replies
MichaelKohler
Frequent Contributor
The code below will read the data in the castlesandSTUFF.xml file. I had to put my own xml file on my server because there was a security error I didn't feel like debugging when using the xml link you provided. Plus there was an error caused by the ":" colon symbol in the lat and long tag of the xml file. the xml reader didn't like it for some reason. But from the code below, you should be able to get started.
 public MainPage()
        {
            InitializeComponent();
            callread();
        }

        private void callread()
        {
            WebClient wc = new WebClient();
            wc.OpenReadAsync(new Uri(" INSERT YOUR XML LINK HERE", UriKind.Absolute));
            wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
        }
        private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            Stream s = e.Result;
            XDocument xd = XDocument.Load(s);
            IEnumerable<XElement> ie = xd.Elements();
            foreach (XElement el in ie)
            {
                IEnumerable<XElement> re = el.Elements();
                foreach (XElement rootElm in re)
                {
                    IEnumerable<XElement> items = rootElm.Elements();
                    foreach (XElement item in items)
                    {
                        XElement title = item.Element("title");
                        XElement desc = item.Element("description");
                        XElement geolat = item.Element("geolat");
                        XElement geolong = item.Element("geolong");
                        MessageBox.Show(title.Value.ToString());

                       //CREATE A POINT HERE AND ADD IT TO A GRAPHIC LAYER IN YOUR MAP
                    }
                }
            }
        }


Once you can read the xml file you can create graphic points and add them to a graphic layer. I didn't include that part because I don't want to rob you of the fun of figuring it out on your own!

Hope it helped some,
Mike
0 Kudos
JohnMorris3
Emerging Contributor

Once you can read the xml file you can create graphic points and add them to a graphic layer. I didn't include that part because I don't want to rob you of the fun of figuring it out on your own!

Hope it helped some,
Mike

 
Mike, You are a gentleman!  Many thanks.  I'm off to try this now.

Oh, and feel free to rob me anytime! 😄 😄  No, you are right, it helps to understand it better taking it in steps.

Best regards,

John
0 Kudos
JohnMorris3
Emerging Contributor
Hi Mike,

I have been looking at where I can put the code... I presume the code goes inside javascript tags... I can't figure where to put it.

I did manage to add a graphics layer using code I got from the site... see below

<esri:Map x:Name="MyMap" Extent="-23, 45, 6, 60" >
        <esri:Map.Layers>
              <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
      Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />             
               
            </esri:Map.Layers>
        </esri:Map>
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I suggest you look first at the interactive samples such this one.
0 Kudos