Link to home
Start Free TrialLog in
Avatar of JCWEBHOST
JCWEBHOST

asked on

xml

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?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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

I suspect the SelectNodes isn't correct, or is some XML missing ?
Avatar of JCWEBHOST
JCWEBHOST

ASKER

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;
    }
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 ?
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...
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>
thats my full xml document
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

SOLUTION
Avatar of John Claes
John Claes
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

 node.Attributes("address"))


Not working getting null ref to object
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks