My.txt file is pipe-delimited ('|', vertical bar) flat text file. Like this: 156025621|Dos|Justamente Tres|Kill Rock Stars|256|PUNK|CD-JEWEL CASE||D Now I have to change this text file into xml file and also I have to add parent-child node for this xml. I have to use Linq to xml and XElement. Please help me out. Learn more about the XML file format, its advantages, and usage compared to HTML files. How to open XML files? We can tell you! File extension.DOC Category Description DOC is a native MS Word text format that supports markup and rich text styling. As opposite to TXT, together with texts DOC file can contain various formatting parameters, tables, images, other graphic elements and charts. Documents of such type are readable by MS Word, free Microsoft Word Viewer and many open source packages like LibreOffice. DOC files can be read and edited on Android OS by Kingsoft Office For Android. Since Word 2007 new, improved format version is used - DOCX. Associated programs AbiWord Apple Pages AppleWorks KWord Microsoft Word StarOffice Developed by Microsoft MIME type application/msword Useful links. Convert Text Files to XML (Any Flat File to XML) Sometimes it's, and other times it's not. For the simple cases, the adapter or one of its relatives is a good choice. But there are several cases where that's just not good enough. For example: • Simple CSV files • When fields are • When there is in the file So let's conquer those together. Suppose your file looks like this bikes_fixed.txt file: 1: MakeModelYearMileage 2: BMWR1150RS200414274 3: KawasakiGPz1100199660234 4: DucatiST2199724000 5: MotoGuzziLeMans200112393 6: BMWR1150R200217439 7: DucatiMonster200015682 8: ApriliaFutura200117320 For display, we've used a ' (raised dot) to represent a space, but notice that although we've broken the text to make the record layout easier to see, there are no line ending markers — no LF's and no CR's. To turn this into XML, we're going to build a custom adapter. Just follow the steps, and look at the pictures — just like. Choose File|New|Convert to XML. Choose the input file. What we're going to do is take a file that is representative of the format we want to convert, and use it as a template. Once we have the adapter built against it, that same definition should work against any file of similar format. Note that sometimes there is sufficient context for Stylus Studio® to determine the basic structure and encoding up front, so it offers to 'guess' for you based on what it knows about certain common file formats. When the file opens, Stylus Studio® will assume a default record width for this fixed-width file, since no record separators are obvious. So we will grab the right-hand margin and drag it to the left until the columns line up. Alternatively, we could open the Properties window and set the width manually (but this is more fun). (click to enlarge) 4. To set the field boundaries, right-click on what looks to be the first character of each field, and choose Begin Field in This Column. Do this once for each field boundary. If you make a mistake, don't worry. That same option will remove the field marker. Or, you can just drag the lines around. The fields need names, and in this case they are right inside the file. So we can tell Stylus Studio® to get them from there by right-clicking anywhere in that first row and choosing Get Field Names from This Row. We could also double-click on the field headings and set them manually, or use the Properties window or even the schema tree (which is beyond the scope of this tutorial). At this point, we're ready to run the adapter. Now let's save and run the adapter against our test file. Choose ConvertToXML|Preview Result, or click on the button. If you haven't already saved it, you will be prompted to save it now. And here is the final result: (click to enlarge). Going from XML to text smells like a job for XSLT - it's a XML-based transformation language that can take an XML input and convert it to anything text-based on the output side. You can read up on XSLT on lots of websites - one of the better tutorials in the one. Since you didn't post any sample XML, I have no clue what your XML looks like, and also no idea what your output should be. But assuming it would look something like: Some Title Some description Keyword1 Keyword2 Keyword3 Keyword4 you could easily write a XSLT transformation to turn that into YourTextFile.txt Some Title Some Description Keyword1,Keyword2,Keyword3,Keyword4 or whatever other format you are looking for. My suggestion would be to use Python. You can use the interpreter to run the pattern while you are setting it up, command line goes along way in setting this sort of thing up properly. Assuming the xml is valid this should allow you the most flexibility with the least hassle. So assuming the following xml format: Document Title Some document content. Test, document, keyword and assuming the output of each document should be: Document Title Some document content.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2018
Categories |