Solved

Convert xml (not standard) to html

Posted on 2012-12-31
4
290 Views
Last Modified: 2013-01-02
Hi,

I request a web service to get a stream of xml whose content i saved in the attached file.
I have this content xml file . suppose i have this stream  saved into XML, and I create XDocument:  
XDocument doc = XDocument.Parse(xml);

 var user = from u in doc.Elements("a:string")
                                       select u;
When i run it, it has exception: ":" not allowed.

My goal is to get the u1,u3,u2,u5,u7 between <a:string>...<a:string>.



Since i got the data which is dynamic changing for different service i made a call.

Which approach i should use: using XSLT or LINQ via XML?

Thanks,
Tran
basicusers.xml
0
Comment
Question by:mtran888
[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
  • 3
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
ID: 38733362
Use an XNamespace. Also, you need to use the Descendants method rather than the Elements method. Elements is for immediate children; Descendants is for any generation of child.

XDocument doc = XDocument.Load("basicusers.xml");
XNamespace ns = "http://schemas.microsoft.com/2003/10/Serialization/Arrays";

var user = from u in doc.Descendants(ns + "string")
            select u;

foreach (var u in user)
{
    Console.WriteLine(u.Value);
}

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38733369
Alternatively, use braces around the namespace:

XDocument doc = XDocument.Load("basicusers.xml");

var user = from u in doc.Descendants("{http://schemas.microsoft.com/2003/10/Serialization/Arrays}string")
            select u;

foreach (var u in user)
{
    Console.WriteLine(u.Value);
}

Open in new window

0
 

Author Closing Comment

by:mtran888
ID: 38734988
Hi Gentlemen,

Thanks for your solution.

I wonder if you  folks can suggest any good book on XML programming?

Regards,
Tran
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38737194
Honestly, all the XML knowledge I've picked up has been found online. I usually end up at W3Schools.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

705 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