Solved

xml

Posted on 2011-09-02
12
470 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
12 Comments
 
LVL 44

Expert Comment

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

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

Author Comment

by:JCWEBHOST
Comment Utility
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
Comment Utility
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
 
LVL 44

Expert Comment

by:AndyAinscow
Comment Utility
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
Comment Utility
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
Comment Utility
thats my full xml document
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:JCWEBHOST
Comment Utility
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
Comment Utility
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
Comment Utility

 node.Attributes("address"))


Not working getting null ref to object
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 167 total points
Comment Utility
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:zaping
zaping earned 167 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now