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
Solved

Convert xml (not standard) to html

Posted on 2012-12-31
4
288 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
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…

838 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