Solved

xml

Posted on 2011-09-02
12
488 Views
Last Modified: 2012-05-12
Hey guys, i can not get the nodes text from my xml document?

here is the document innerxml

<marker id="1" r_name="Rit Restaurant" address="232 Canehaven drive" area="ROSSLYN" location="ERASMUS VILLAGE" p_code="0250" Latitude="-25.6236510" Longitude="28.0887790" />

here is my c# code :

 XmlDocument Document = new XmlDocument();
        Document = XmlData(Latitude, Longitude);

        if (Document != null)
        {
            XmlNodeList nodeList = Document.SelectNodes("markers");

            foreach (XmlNode node in nodeList)
            {
                string address = node.SelectSingleNode("address").InnerText;
            }
        }


please help?

i cant get the address?
0
Comment
Question by:JCWEBHOST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36472446
>>  Document.SelectNodes("markers");
>>  <marker id="1"...

I suspect the SelectNodes isn't correct, or is some XML missing ?
0
 

Author Comment

by:JCWEBHOST
ID: 36472465
here my code:

    public void searchLocationsNear(GeoCode latlng)
    {
        double Latitude = latlng.Placemark.coordinates.lat;
        double Longitude = latlng.Placemark.coordinates.lng;

        XmlDocument Document = new XmlDocument();
        Document = XmlData(Latitude, Longitude);

        if (Document != null)
        {
            XmlNodeList nodeList = Document.SelectNodes("markers");

            foreach (XmlNode node in nodeList)
            {
                string address = node.SelectSingleNode("address").InnerText;
            }
        }
    }

    public XmlDocument XmlData(double dmlSearchLatitude, double dmlSearchLongitude)
    {
        m.DmlSearchLatitude = dmlSearchLatitude;
        m.DmlSearchLongitude = dmlSearchLongitude;
        m.Area = ddArea.SelectedItem.Text;

        XmlReader rdrXMLLocations = null;
        rdrXMLLocations = m.proc_Location_List();

        Response.Expires = 0;
        Response.ContentType = "text/xml";
        XmlDocument oDocument = new XmlDocument();
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        using (rdrXMLLocations)
        {
            while (!rdrXMLLocations.EOF)
            {
                rdrXMLLocations.MoveToContent();
                sb.Append(rdrXMLLocations.ReadOuterXml());
            }
            rdrXMLLocations.Close();
        }

        oDocument.LoadXml(sb.ToString());

        return oDocument;
    }
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36472482
OK, and why did you post that code ??


repeat:
>>  Document.SelectNodes("markers");
>>  <marker id="1"...

I suspect the SelectNodes isn't correct, or is some XML missing ?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 36472484
Or put another way the code you posted in the question look rather like:

Hi, I want to find objects of type X with the following code, by the way this is how some other object of type A is defined...
0
 

Author Comment

by:JCWEBHOST
ID: 36472491
here my xml

(Document).InnerXml

vaule
<markers><marker id="1" r_name="Rit Restaurant" address="232 Canehaven drive" area="ROSSLYN" location="ERASMUS VILLAGE" p_code="0250" Latitude="-25.6236510" Longitude="28.0887790" /></markers>
0
 

Author Comment

by:JCWEBHOST
ID: 36472517
thats my full xml document
0
 

Author Comment

by:JCWEBHOST
ID: 36472555
here is my javascript which i am trying to convert to c# code:

 
var markers = xml.documentElement.getElementsByTagName('marker');

            if (markers.length == 0) 
            {
                sidebar.innerHTML = 'No results found.  Please try widening your search area.';
                map.setCenter(new GLatLng(startingLat, startingLng), startingZoom);
                return;
            }

            var bounds = new GLatLngBounds();
            for (var i = 0; i < markers.length; i++) 
            {
                var address = markers[i].getAttribute('address');
                var area = markers[i].getAttribute('area');
                var location = markers[i].getAttribute('location');
                var p_code = markers[i].getAttribute('p_code');
                var point = new GLatLng(parseFloat(markers[i].getAttribute('Latitude')), parseFloat(markers[i].getAttribute('Longitude')));

                var marker = createMarker(point, address, area, location, p_code);

                map.addOverlay(marker);
                var sidebarEntry = createSidebarEntry(marker, address, area, location);
                sidebar.appendChild(sidebarEntry);
                bounds.extend(point);
            }

Open in new window

0
 
LVL 10

Assisted Solution

by:John Claes
John Claes earned 166 total points
ID: 36472560
First of all.


The foreach loop is looping the Markers
so until there it looks ok.

then you are searching in your Marker for the Node "address" ??
there are no child Nodes only attributes.
so you need to take the attribute value (something like node.Attributes("address"))

poor beggar
0
 

Author Comment

by:JCWEBHOST
ID: 36472578

 node.Attributes("address"))


Not working getting null ref to object
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 167 total points
ID: 36472768
OK, some XML was missing - That bit looks like it should work.

Are you actually getting any nodes returned at:
XmlNodeList nodeList = Document.SelectNodes("markers");
0
 
LVL 1

Assisted Solution

by:Vitor Silva
Vitor Silva earned 167 total points
ID: 36477543
Shouldn't you be doing XmlNodeList nodeList = Document.SelectNodes("markers/marker");, because you want to be set on the nodes "marker" inside the node "markers" and that's where you want loop.
and then loop trough the nodes to get the sttribute address using node.Attributes("address").
0
 

Author Closing Comment

by:JCWEBHOST
ID: 36482766
Thanks
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question