Solved

Convert xml (not standard) to html

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio Exe Issue, 12 27
Event ID 10010 3 52
Launching Internet Explorer inPrivate mode using VBA 14 394
WPF issue with Trigger 2 96
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 …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

862 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

23 Experts available now in Live!

Get 1:1 Help Now