views:

100

answers:

2

I have some sample xml data, for ex:

<?xml version="1.0" encoding="utf-8"?>
<Account>
<User>
  <FirstName>John</FirstName>
  <LastName>Doe</LastName>
</User>
<LoginDetails Sequence="1">
  <LoginDate>01/01/09</LoginDate>
  <Status>Successful</Status>
</LoginDetails>
<LoginDetails Sequence="2">
  <LoginDate>01/02/09</LoginDate>
  <Status>Failed</Status>
</LoginDetails>
</Account>

I have a schema file for this xml. I'd like to provide functionality that allows an end user to do the following:

  1. Define which elements to display.
  2. Define a label for each element.
  3. Give the user the ability to save this information and then utilize it at runtime in my application when I load the real xml data.

I'm thinking maybe I can use LINQ or Dynamic LINQ to do this. I think I can first parse the xml or use the schema to show a list of all the nodes (possibly in a tree view?) and let the user check which element they want to display and type in a label.

Does this sound like a good idea? I was thinking to use XSLT but I think it might be easier in LINQ. Can anyone provide me some links or information that would help me achieve this? Are there any better solutions out there?

A: 

You could use XSLT - just keep in mind that it's hard to read and maintain. If you do use XSLT I recommand you can use a good tool (if you can afford it) called MapForce that will help you create the XSLT file using a WYSIWYG editor.

Dror Helper
Thanks for your response! Yeah, I was trying XSLT but I thought of Linq b/c I have a hard time working with XSLT and I think it would be easier for other programmers who would end up working with this project. The problem I have is I'm not exactly sure how to do it. I know it should be possible from what I've read but I need some help getting started.
As described, your task is much more suitable for XSLT than LINQ to XML. Particularly since XSLT _is_ the user config on how to display the data in this case.
Pavel Minaev
So I should generate an xslt based on what the user selects from the user interface (treeview or list or whatever) and then save it? If so, what if they want to make reload whatever settings they had done and make a change. It seems kind of awkward to read the xslt and then try to re-create the settings that were chose in the user interface, no? I was thinking if I could map some objects to the xml and then use that to serialize the user's settings, it would be easier to retrieve and display again?
Oh, I see what you mean now. By "end-user customizable", I assumed some fairly advanced end users (capable of just editing XSLT to get the output they want - this is the most flexible option). If you want it to be UI-driven, that's another story, though it's still probably doesn't change the fact that XSLT (parametrized, in this case) may be more suitable for transformations than LINQ.
Pavel Minaev
A: 

The end-user doesn't need to know XSLT but I do need to provide a simple way for them to decide which element to display or not.

So it seems the best answer is to create a UI which allow the user to select which nodes they want to display and then simply serialize this information to a simple xml file so I can de-serialze it if they need to reload the settings page and change something later.

Then I can generate and XSLT based on these settings and utilize it for transforming the incoming xml? Maybe, I can provide an ability to directly edit the XSLT for advanced users?

Does this seem resonable?

Linq Noob
Yes, it does seem quite reasonable. Allowing for user to directly provide XSLT is a nice touch as there are quite a few powerful tools for "visual" XSLT editing that let user start with input XML, and configure the way he wants output to be (IIRC Altova offers something like that). For the case where you provide your own visual editor and save them to config XML, you could in fact use XSLT to convert that XML to XSLT as well :)
Pavel Minaev