


Detailed introduction to the benefits of converting data into XML format
We often encounter situations where we need to process data saved or transmitted in various formats (from comma or tab-delimited files to more loadable formats), and you need to respond to each format. parser. This shortcoming slows down development and can lead to errors. One solution is to convert data in commonly used formats into xml documents, and then save, process or convert them into other formats.
An example
There are now many data formats that implement data saving, exporting, importing and transferring functions within or between software. The most common are delimited formats, such as comma or tab-delimited data formats and fixed-length data formats. Suppose we have an address book program that provides functionality for exporting data into comma-separated and fixed-length formats.
In comma-separated format, commas are used to separate different fields in the same data record, as shown in Listing A. In fixed-length data format, each field of the record should have a standard length. Listing B shows an address book in fixed-length format.
Create XML Document
Now, let us parse the input data and convert it into an XML document. The XML document (ie org.w3c.dom.Document) is the primitive data type of the entire Document Object Model (DOM), and it provides access to document data.
You can create a document corresponding to your data by executing the buildDocument(InputStream is) method, as shown in code listing C. This method reads the input data stream line by line and analyzes it line by line according to the given grid.
If you want to parse delimited format data, you need to create an instance of the class whose constructor is PlainTextToXmlFormatter(String[ ] colName, String delim), and its delimiter can be any string. In the case of fixed-length formats, you should use the second constructor PlainTextToXmlFormatter(String[ ] colName,int[ ] colLen), which takes an array of field lengths as a parameter. In the address book example we gave, the lengths of each field are 10, 10, 30, and 10 characters respectively. The parameter colName is an array that stores the names of the target data records. In the example we gave, the names are first name (firstName), last name (lastName), email, and phone number (phone).
The actual parsing process of converting data rows into data symbols is the process of executing the getStringArray(String read, String delim) or parseFixedLengthMessage(String read, int[ ] colLen) method. The return value is a String array, which is obtained by decomposing the given input by the above two methods. If the data format is incorrect, an exception will be thrown and the parsing error will terminate. Call the setSkipError(true) method to ignore the exception and complete the data parsing process. Calling this method prevents the exception from being thrown, but it still allows the program to print error information to the error output stream.
When lines are parsed into tags, they are added to the XML document as elements of the XML document. Each line of records placed into the element has a default name line. You can also call setDataLineName() to specify a name. Each data record is a column element, the name of the column element is provided by the corresponding class constructor, and the child elements are added to the row element.
After the input data is completely read, you have a valid XML document that you can further process. Now, since the data is organized in the well-known tree structure, working with it is very simple. For example, you can send this document to a third party. As long as the third party knows the document type definition (Document Type Definition, DTD) of the document, then he can easily process the document. You can also call the writeDocument(Document doc, OutputStream osOut) method to save this document. Code Listing D gives an example of saving an XML document to a file.
Use XSLT transformation to view data
You can also convert XML data into other formats and use different views to represent its content. The simplest method is to use XSLT transformation, which provides a powerful tree-oriented transformation language implementation that can transform XML instances using one vocabulary into simple text, HTML, or XML using other vocabularies.
For a given XML input, you can use the XSLT language to create your desired output. For example, you can convert XML data into an HTML document by executing transformData(InputStream xmlIn, InputStream xslIn, OutputStream transfOut). Listing E provides an example of an XSLT transformation, while Listing F gives an HTML view of an address book entry.
Simplify data management
In this article, we learned how to convert commonly used format data into XML documents by analyzing the PlainTextToXmlFormatter class. We also saw how to represent XML documents in different views with the help of XSLT transformations. When you need to process data in various formats, adopting the above technology may be a good solution, saving you valuable time and reducing the possibility of errors.
The above is a detailed introduction to the benefits of converting data into XML format. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

This week, FigureAI, a robotics company invested by OpenAI, Microsoft, Bezos, and Nvidia, announced that it has received nearly $700 million in financing and plans to develop a humanoid robot that can walk independently within the next year. And Tesla’s Optimus Prime has repeatedly received good news. No one doubts that this year will be the year when humanoid robots explode. SanctuaryAI, a Canadian-based robotics company, recently released a new humanoid robot, Phoenix. Officials claim that it can complete many tasks autonomously at the same speed as humans. Pheonix, the world's first robot that can autonomously complete tasks at human speeds, can gently grab, move and elegantly place each object to its left and right sides. It can autonomously identify objects

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,
