alfonsopink
New Member
I have a Web Service in PHP that reads a XML file of albums, and simply returns it as a string to my ASP.NET web form. Now, the sending and receiving is fine.The problem is that now I want to parse this data in order to save the new albums and other information (such as Genre, Artist, and Songs) to my database attached to my ASP.NET web site, and it's giving me a headache.Here's the code of the Web Service client:\[code\]protected void btnGetAlbums_Click(object sender, EventArgs e) { phpPublisher.albums albums = new albums(); string result = albums.getAlbums(); if (String.IsNullOrEmpty(result)) { txtResult.Text = "No albums found"; } else { // parse XML var xml = XElement.Parse(result); var albumList = xml.Descendants("Albums") .Elements("Album"); if (albumList.Count() > 0) { txtResult.Text = "Has at least 1 album!"; } } }\[/code\]This is just very 'demo'-ish code for now, I haven't even tackled the database inserting and all that because I can't even parse the data.If I output the \[code\]xml\[/code\] variable in my \[code\]txtResult\[/code\] textbox, it shows:\[code\]<Albums> <Album> <AlbumTitle>Stripped</AlbumTitle> <AlbumArtist>Christina Aguilera</AlbumArtist> <AlbumGenre>Pop</AlbumGenre> <AlbumSongs> <AlbumSong>Beautiful</AlbumSong> </AlbumSongs> </Album></Albums>\[/code\]All in one line, which is incredibly frustrating. I don't know if it can even parse the data like this...what I'd like to do in the PHP side is just send a XML data object that ASP.NET could read. Is this possible? Here's what my PHP web service function looks like (it returns a string). \[code\]function getAlbums() { $dataSource = "albums.xml"; if(file_exists($dataSource)) { $xml = simplexml_load_file($dataSource); $dom = new DOMDocument('1.0'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml->asXML()); return $dom->saveXML(); } else { return null; } }\[/code\]Any help is appreciated. Thank you.P.S. When I execute \[code\]albumList.Count()\[/code\], it returns 0, which means the list contains no elements, so there's a parsing error somewhere.