将XML转换为特定的XML架构?

时间:2022-12-14 17:17:07

Sorry but I am not knowledgeable about XML at all, although I do code in HTML, CSS, and a little jQuery.

对不起,但我根本不了解XML,虽然我用HTML,CSS和一些jQuery编写代码。

I have an API that outputs JSON data, that I need to transfer over to a specific XML schema. I have found a JSON to XML converter, but it does not convert to the specific XML format that I need. Any help will be greatly appreciated.

我有一个输出JSON数据的API,我需要将其转移到特定的XML模式。我找到了一个JSON到XML转换器,但它没有转换为我需要的特定XML格式。任何帮助将不胜感激。

Just to note, the XML schema file provided to me is .XSD.

需要注意的是,提供给我的XML模式文件是.XSD。

1 个解决方案

#1


-1  

You will need to define the transformation in an .xslt file in order to convert. It is not possible to create the required .xslt transformation file automatically (except for simple and trivial cases) from an analysis of the .xsd file. They are two different things completely.

您需要在.xslt文件中定义转换才能进行转换。从.xsd文件的分析中无法自动创建所需的.xslt转换文件(除了简单和简单的情况)。它们完全是两件不同的事情。

You can solve your problem in two steps:

您可以通过两个步骤解决问题:

Step 1: Understand the transformations needed and manually create the required .xslt file. Here is a good tutorial https://docs.oracle.com/javase/tutorial/jaxp/xslt/transformingXML.html

步骤1:了解所需的转换并手动创建所需的.xslt文件。这是一个很好的教程https://docs.oracle.com/javase/tutorial/jaxp/xslt/transformingXML.html

Step 2: Directly transform your JSON data to the desired XML using your .xslt file as described here https://dnovatchev.wordpress.com/2007/07/05/transforming-json/

步骤2:使用.xslt文件将JSON数据直接转换为所需的XML,如此处所述https://dnovatchev.wordpress.com/2007/07/05/transforming-json/

OR

要么

Create an intermediate .xml file from the JSON data and transform the intermediate .xml file to the desired .xml output file using the .xslt you created, a fairly straightforward task.

从JSON数据创建一个中间.xml文件,并使用您创建的.xslt将中间.xml文件转换为所需的.xml输出文件,这是一项相当简单的任务。

#1


-1  

You will need to define the transformation in an .xslt file in order to convert. It is not possible to create the required .xslt transformation file automatically (except for simple and trivial cases) from an analysis of the .xsd file. They are two different things completely.

您需要在.xslt文件中定义转换才能进行转换。从.xsd文件的分析中无法自动创建所需的.xslt转换文件(除了简单和简单的情况)。它们完全是两件不同的事情。

You can solve your problem in two steps:

您可以通过两个步骤解决问题:

Step 1: Understand the transformations needed and manually create the required .xslt file. Here is a good tutorial https://docs.oracle.com/javase/tutorial/jaxp/xslt/transformingXML.html

步骤1:了解所需的转换并手动创建所需的.xslt文件。这是一个很好的教程https://docs.oracle.com/javase/tutorial/jaxp/xslt/transformingXML.html

Step 2: Directly transform your JSON data to the desired XML using your .xslt file as described here https://dnovatchev.wordpress.com/2007/07/05/transforming-json/

步骤2:使用.xslt文件将JSON数据直接转换为所需的XML,如此处所述https://dnovatchev.wordpress.com/2007/07/05/transforming-json/

OR

要么

Create an intermediate .xml file from the JSON data and transform the intermediate .xml file to the desired .xml output file using the .xslt you created, a fairly straightforward task.

从JSON数据创建一个中间.xml文件,并使用您创建的.xslt将中间.xml文件转换为所需的.xml输出文件,这是一项相当简单的任务。