简体   繁体   中英

Is it possible to convert json file to XML to import in wordpress?

I have used web scraping to get quiz on internet. And I want to import them on wordpress

Here's an example of a piece of an XML file that has been exported from Wordpress

<?xml version="1.0" encoding="utf-8"?>
<wpProQuiz><header version="0.28" exportVersion="1" ld_version="4.1.2" LEARNDASH_SETTINGS_DB_VERSION="2.5"/><data><quiz><title titleHidden="true"><![CDATA[PSPO Exam Blanc #4 (with comments)]]></title><text><![CDATA[ AAZZAAZZ]]></text><resultText gradeEnabled="true"><text prozent="0"><![CDATA[]]></text></resultText><btnRestartQuizHidden>false</btnRestartQuizHidden><btnViewQuestionHidden>false</btnViewQuestionHidden><questionRandom>false</questionRandom><answerRandom>false</answerRandom><timeLimit>0</timeLimit><showPoints>false</showPoints><statistic activated="true" ipLock="0"/><quizRunOnce type="0" cookie="false" time="0">false</quizRunOnce><numberedAnswer>false</numberedAnswer><hideAnswerMessageBox>false</hideAnswerMessageBox><disabledAnswerMark>false</disabledAnswerMark><showMaxQuestion showMaxQuestionValue="0" showMaxQuestionPercent="false">false</showMaxQuestion><toplist activated="false"><toplistDataAddPermissions>1</toplistDataAddPermissions><toplistDataSort>1</toplistDataSort><toplistDataAddMultiple>false</toplistDataAddMultiple><toplistDataAddBlock>0</toplistDataAddBlock><toplistDataShowLimit>0</toplistDataShowLimit><toplistDataShowIn>0</toplistDataShowIn><toplistDataCaptcha>false</toplistDataCaptcha><toplistDataAddAutomatic>false</toplistDataAddAutomatic></toplist><showAverageResult>false</showAverageResult><prerequisite>false</prerequisite><showReviewQuestion>true</showReviewQuestion><quizSummaryHide>true</quizSummaryHide><skipQuestionDisabled>true</skipQuestionDisabled><emailNotification>0</emailNotification><userEmailNotification>false</userEmailNotification><showCategoryScore>false</showCategoryScore><hideResultCorrectQuestion>false</hideResultCorrectQuestion><hideResultQuizTime>false</hideResultQuizTime><hideResultPoints>false</hideResultPoints><autostart>false</autostart><forcingQuestionSolve>false</forcingQuestionSolve><hideQuestionPositionOverview>true</hideQuestionPositionOverview><hideQuestionNumbering>true</hideQuestionNumbering><sortCategories>false</sortCategories><showCategory>false</showCategory><quizModus questionsPerPage="0">2</quizModus><startOnlyRegisteredUser>true</startOnlyRegisteredUser><forms activated="false" position="0"/><questions><question answerType="single"><title>

<![CDATA[Question 1]]></title><points>1</points><questionText><![CDATA[<p>What provides guidance to the Developers on why they are building the Increment?<br />(choose the best answer)</p>]]></questionText><correctMsg><![CDATA[<p>The Sprint Goal is an objective set for the Sprint that can be met through the implementation of Product Backlog. It provides guidance to the Scrum Team on why it is building the Increment.</p>]]></correctMsg><incorrectMsg><![CDATA[<p>The Sprint Goal is an objective set for the Sprint that can be met through the implementation of Product Backlog. It provides guidance to the Scrum Team on why it is building the Increment.</p>]]></incorrectMsg><tipMsg enabled="false"><![CDATA[]]></tipMsg><category/><correctSameText>true</correctSameText><showPointsInBox>false</showPointsInBox><answerPointsActivated>false</answerPointsActivated><answerPointsDiffModusActivated>false</answerPointsDiffModusActivated><disableCorrect>false</disableCorrect><answers><answer points="1" correct="true"><answerText html="false"><![CDATA[The Sprint Goal]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[The Product Owner]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[The Scrum Master]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[The Sprint Backlog]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer></answers></question><question answerType="single"><title>
<![CDATA[Question 2]]></title><points>1</points><questionText><![CDATA[<p>How long does a Product Backlog exists?<br />(choose the best answer)</p>]]></questionText><correctMsg><![CDATA[<p>The Product Backlog is dynamic; it constantly changes to identify what the product needs to be appropriate, competitive, and useful. If a product exists, its Product Backlog also exists.</p>]]></correctMsg><incorrectMsg><![CDATA[<p>The Product Backlog is dynamic; it constantly changes to identify what the product needs to be appropriate, competitive, and useful. If a product exists, its Product Backlog also exists.</p>]]></incorrectMsg><tipMsg enabled="false"><![CDATA[]]></tipMsg><category/><correctSameText>true</correctSameText><showPointsInBox>false</showPointsInBox><answerPointsActivated>false</answerPointsActivated><answerPointsDiffModusActivated>false</answerPointsDiffModusActivated><disableCorrect>false</disableCorrect><answers><answer points="1" correct="true"><answerText html="false"><![CDATA[As long as the Product exists.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[Until the final Product Release.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[Not more than 3 years.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[As long as a Developer is doing work from it.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer></answers></question><question answerType="single"><title>
<![CDATA[Question 3]]></title><points>1</points><questionText><![CDATA[<p>Peter has been asked to take the Product Owner role of a large<br />product initiative. 4 teams new to Scrum will be building this product. He has created the initial Product Backlog but is unsure of how to minimize the dependencies between the Scrum Teams.<br />Which of the following would be the best advice to give Peter?<br />(choose the best answer)</p>]]></questionText><correctMsg><![CDATA[<p>Because the Developers are the ones doing the work, they would be the best ones to help the Product Owner analyze and reduce the dependencies between the work to be done.</p>]]></correctMsg><incorrectMsg><![CDATA[<p>Because the Developers are the ones doing the work, they would be the best ones to help the Product Owner analyze and reduce the dependencies between the work to be done.</p>]]></incorrectMsg><tipMsg enabled="false"><![CDATA[]]></tipMsg><category/><correctSameText>true</correctSameText><showPointsInBox>false</showPointsInBox><answerPointsActivated>false</answerPointsActivated><answerPointsDiffModusActivated>false</answerPointsDiffModusActivated><disableCorrect>false</disableCorrect><answers><answer points="1" correct="false"><answerText html="false"><![CDATA[The Product Owner creates separate Product Backlogs for each team.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[The Product Owner identifies the dependent items and re-order the Product Backlog items for the Scrum Teams.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="true"><answerText html="false"><![CDATA[The Product Owner works with the Developers from all Scrum Teams on how to best analyze and break apart the work.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[The Product Owner has the Technical Leads determine which items will be assigned to which team.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer><answer points="0" correct="false"><answerText html="false"><![CDATA[The Product Owner notifies the Scrum Master so he/she can resolve the impediment.]]></answerText><stortText html="false"><![CDATA[]]></stortText></answer></answers></question><question answerType="single"><title>
<![CDATA[Question 4]]>

and JSON file looks like that :

[
    {
        "question": "Who supports the Scrum Master in removing impediments?\n(choose the best three answers)\nChoose ALL answers that apply.",
        "correct": [
            "Management",
            "The Product Owner",
            "The Developers"
        ],
        "incorrect": [
            "The customer"
        ],
        "explic": "The Developers can help the Scrum Master because of their understanding of how the work is done and their internal interactions with each other. Some impediments are rooted in external causes and that's why the Scrum Master might need to have the senior management's support in removing them. The Product Owner can also support the Scrum Master by managing stakeholder expectations."
    },
    {
        "question": "Which TWO of the following statements are true?\n(choose the best two answers)\nChoose ALL answers that apply.",
        "correct": [
            "Early feedback enables agile teams to deliver features with the highest business value first, because the customer maintains focus on features with the highest system value.",
            "Early feedback makes it more likely that the system built is what the customer wanted because they are given the opportunity to make changes throughout the iteration."
        ],
        "incorrect": [
            "Early feedback reduces costs because it decreases the amount of time needed for system testing.",
            "Early feedback gives the Developers more time to develop new system features because they spend less time reworking features expected in a given iteration."
        ],
        "explic": "Agile teams are highly flexible and adaptive. These strengths continue operating in single, several, many, and networks of teams that develop, release, operate and sustain the work and work products of thousands of people. They collaborate and interoperate with team members and stakeholders in order to maximize opportunities of success."
    }

]

So in this case I can only import XML files, I guess I am supposed to convert this JSON file in XML, but I dont know if it s possible, and if yes do you have an idea please?

It's certainly possible, but it's a pretty weird XML format.

I started doing an XSLT 3.0 stylesheet for you, but I couldn't work out the correspondence between the input and the output, so I gave up. XSLT 3.0 can parse and process JSON input, and can generate XML output, so it's got everything you need.

The main technical difficulties are:

(a) the XML format has elements containing CDATA containing what appears to be HTML. You can construct that in XSLT 3.0 - use the serialize() function with method="html" to construct a string containing HTML, and then copy this into the XML result tree. (By default the HTML will be escaped using entity references rather than CDATA, but the chances are that Wordpress will accept either; if not, you can force CDATA by using cdata-section-elements in xsl:output

(b) the XML format also makes liberal use of CDATA where it isn't needed. Chances are that this was pure laziness on the part of the people writing the export software, and it's not actually needed when importing; but again, if you do need it, use xsl:output/cdata-section-elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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