How to get data from XML files into business objects? - asp.net-mvc-2

I need to build a view in my MVC 2 application that allows a user to upload an XML file. The XML files will conform to an XSD. I need to parse the XML and extract data to populate C# objects that will then be sent off to a web service.
My question is...since I know the exact "format" of the XML files, because of the XSD, is there some easier way to "move" the data in the XML files into my business objects?
I read about some Linq-to-XSD project, but it appears to have been abandoned. Linq-to-XML doesn't seen very helpful, since I still have to "walk" through the entire XML document to get all the data.
Surely there is an easier way?

http://linqtoxsd.codeplex.com/
here is a linq to xsd project on codeplex
http://www.codeproject.com/KB/linq/LINQ_to_XSD.aspx
another on code project
http://www.hanselman.com/blog/LINQToEverythingLINQToXSDAddsMoreLINQiness.aspx
and scott hanselmen talks about this. Between these links(no pun intended) you should be alright

Related

browse file path spring webflow

I am currently working on a spring webflow application. In this project there are certain entities that point to a document that contains more information about that entity. However sometimes this document is not provided. In that case the user must be able to research the file for himself.
I need a simple way to let the user search a file and then save the filepath of the selected file into the database.
For most of our components we use richfaces but I don't really like the richfaces <fileUpload> because it's too big and too complex. I have seen that icefaces and tomahawk provide nice solutions but our application is limited to richfaces.
I thought of just using the normal:
<form:form> <input type="file> </form:form>"
but I don't know how I can get the information from that submitted form into my bean. I hoped that I could trigger an event once the file had been selected and then use a listener in my bean that would read the filename from the event. However I cannot find the syntax to do this (I don't even know if this is possible).
Can anyone help me? I know I can just do it with richfaces but I don't think that the client would like that enormous form to just select a filepath
why don't you use a simple jsp file upload?
http://www.tutorialspoint.com/jsp/jsp_file_uploading.htm

Web.config overwritten

I have a web.config for my website. I just made a web service which likes to overwrite the previous one. From what I can understand I need an xml transform here. I have read several sites and I am confused as how to complete this. One reference. Would love some insight, thanks in advance.
If you want to add or change something in web.config you don't need any XSL(T) because your output format is still XML.
Transformation (XSLT) is mainly for presenting XML data in different format.
What yo need is basic XML editing functionality. Parse to DOM, add/change nodes, save.

Is there an API to read an EDMX file

If I have an .edmx file, is there a way to programmatically access it? I could use XDocument but maybe there is already an api for this?
EDMX file is only for designer. It is even not distributed with your application as is. EDMX contains four components - SSDL, MSL, CSDL and designer information. First three components are extracted during building application and are stored either as resource XML files in the assembly or shipped as external XML files. These files can be read as any other XML files. The only API (present in .NET) which can load them is EntityConnection / MetadataWorkspace in EF.
Library for Object access to edmx
This worked for me fairly well to loop through the entities and generate code tiers from their definitions.. It's really a gold mine for code generation though I wish the built in EF stuff was open source. I can't quite figure out how to create C# objects based on stored procedure results the way EF does.

Attempting to Pre-load Data into Core Data Store

Sup fellas, I am using the script that a fellow stack overflow user posted here(the post by kalperin) to pre-load data to an SQL Lite store. So I have a command-line utility project that I am using and I have an iPhone application in which I successfully parsed my .plist file and stored it in Core Data, and I am trying to copy over code from my iPhone application to this command-line utility(the plist parsing parts at least). The data model I have made looks like so:
Those two classes inherit from ParkingRegionOverlay which requires the MapKit framework which is not addable to a project of this type(as far as I know). So my questions:
How would I bypass this problem(i.e. How do I get the Mapkit framework as part of my command-line utility project?)?
Do I need to include my .xcdatamodel file in the command-line utility project and reference it in any way? If someone wouldn't mind shedding some light in this area it would be greatly appreciated, as I think I do need my project to know about the data model, but am not quite sure.
Thanks in advance for any help!
you absolutely need the xdatamodel file in your project. It will be "compiled" into a momd file and included in your application bundle. Core Data needs this to know what your data model looks like (that's the whole point of the data model file).
This might help you, too: Can't find momd file: Core Data problems
Also, why do you mix Model and View by having your data model classes inherit from an Overlay class. It seems that you can solve your problem simply by adhering to MVC practices.
Cheers,
Johannes

Best Way to Parse HTML to XML

Essentially, I currently have an iPhone app that can query and parse an XML file on my server. Right now, I currently have to manually update and upload my XML file every morning so my users can have the updated information. I would like to automate this process, which would essentially entail parsing various websites (NYTimes, iAmBored.com, etc), outputting the relevant information from each of these websites to an XML file, and uploading that file to my server.
Does anyone know the best way to accomplish this (parsing HTML to an XML file). Since I am a beginner, I'm not sure what languages this requires or what is the best way to do this?
Thanks a lot in advance!
You can try to translate HTML to XHTML (XHTML is based on XML so it's XML with some rules defined in a DTD).
You can also try to parse directly HTML with a SGML parser (As XHTML is based on XML, HTML is based on SGML).
The links are provided as inspiration.
If the content you need to scrape is in XHTML then you can easily use the XSLT language to transform original content in what you need inside the XML you provide to your users.
Otherwise any kind of scraping and XML producing solution will be fine, every programming language has its support to do such things.. but you could use XPath to select the elements you need from the page and then save them inside the output file.
Can you get what you need from the RSS/Atom feeds? That will simplify things greatly because they are XML rather than HTML and can be parsed by a standard XML parser. Of course, descriptions embedded inside RSS feeds will be HTML, so depending on your application, that may be when you need to parse HTML.
XSLT is a domain-specific programming language designed for processing XML, but you can also use any programming language that includes an XML parser for the task.
TagSoup - Just Keep On Truckin'
...a SAX-compliant parser written in Java
that, instead of parsing well-formed
or valid XML, parses HTML as it is
found in the wild: poor, nasty and
brutish, though quite often far from
short.
TagSoup is designed for people
who have to process this stuff using
some semblance of a rational
application design.
By providing a SAX
interface, it allows standard XML
tools to be applied to even the worst
HTML. TagSoup also includes a
command-line processor that reads HTML
files and can generate either clean
HTML or well-formed XML that is a
close approximation to XHTML.
Also, Taggle, a TagSoup in C++, available now