Solved

xml

Posted on 2011-09-02
12
477 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
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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:zaping
zaping 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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