?
Solved

Convert xml (not standard) to html

Posted on 2012-12-31
4
Medium Priority
?
296 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 2000 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 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