Solved

Convert xml (not standard) to html

Posted on 2012-12-31
4
283 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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 500 total points
Comment Utility
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 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
Hi Gentlemen,

Thanks for your solution.

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

Regards,
Tran
0
 
LVL 74

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

16 Experts available now in Live!

Get 1:1 Help Now