简体   繁体   English

解析和转换的区别?

[英]Difference between parsing and transformation?

I'm wondering what is the difference between data parsing and transformation .我想知道数据解析转换之间有什么区别。

For example, if I need to convert data from XML format to JSON format will it be a transformation or parsing?例如,如果我需要将数据从 XML 格式转换为 JSON 格式,它是转换还是解析?

Transformation is a mapping from one form to another.转换是从一种形式到另一种形式的映射。

  • An XSLT transformation maps from XML to JSON, HTML, (different) XML, etc. XSLT转换从 XML 映射到 JSON、HTML、(不同的)XML 等。

Parsing is an analysis of a sequential form to identify structural parts.解析是对顺序形式的分析以识别结构部分。

  • An XML parser reads XML and identifies its elements, attributes, and other parts. XML解析器读取 XML 并识别其元素、属性和其他部分。

Data conversion is fundamentally a transformation .数据转换从根本上来说是一种转换 Note, though, that transformations often leverage structure identified during parsing of the input form to create the output form.但请注意,转换通常利用在解析输入表单期间识别的结构来创建输出表单。

Parsing technically is the process of establishing the logical structure of the textual input: for example establishing that <ab="3"/> represents an element named a containing an attribute named b whose value is 3.从技术上讲,解析是建立文本输入的逻辑结构的过程:例如,确定<ab="3"/>表示名为 a 的元素,其中包含名为 b 的属性,其值为 3。

Unfortunately the term seems to be increasingly misunderstood, and programmers without formal computer science training often misuse the term to mean almost any processing of the parsed data: we see questions on SO saying "I am writing a parser", when actually they are writing an application that consumes the output of a parser.不幸的是,这个术语似乎越来越被误解,没有经过正规计算机科学培训的程序员经常误用这个术语来表示对解析数据的几乎任何处理:我们看到关于 SO 的问题说“我正在编写一个解析器”,而实际上他们正在编写一个消耗解析器输出的应用程序。

Converting XML to JSON is a three-stage process: parsing the XML, transforming the resulting data structure to a different data structure, and then serializing the transformed data structure into JSON syntax.将 XML 转换为 JSON 是一个三个阶段的过程:解析 XML,将生成的数据结构转换为不同的数据结构,然后将转换后的数据结构序列化为 JSON 语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM