0

I want to split the following xml file into 4 seperate parts (I needed to put link because its to long for posting here :

https://www.dropbox.com/s/dzqyab0wewpuf5t/1547917556__0__qti_166292.xml?dl=0

I want to get out the following parts: Part 1 :




<!DOCTYPE questestinterop SYSTEM "ims_qtiasiv1p2p1.dtd">

<!--Generated by ILIAS XmlWriter-->

<questestinterop>


<item title="titel" maxattempts="0" ident="il_0_qst_152800">

<qticomment>beschreibung</qticomment>

<duration>P0Y0M0DT0H1M0S</duration>


<itemmetadata>


<qtimetadata>


<qtimetadatafield>

<fieldlabel>ILIAS_VERSION</fieldlabel>

<fieldentry>5.3.8 2018-08-29</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>QUESTIONTYPE</fieldlabel>

<fieldentry>CLOZE QUESTION</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>AUTHOR</fieldlabel>

<fieldentry>Patrick Maik Mächler</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>additional_cont_edit_mode</fieldlabel>

<fieldentry>default</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>externalId</fieldlabel>

<fieldentry>5c3f83ce4b6880.97213190</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>textgaprating</fieldlabel>

<fieldentry>ci</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>fixedTextLength</fieldlabel>

<fieldentry>1</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>identicalScoring</fieldlabel>

<fieldentry>1</fieldentry>

</qtimetadatafield>


<qtimetadatafield>

<fieldlabel>combinations</fieldlabel>

<fieldentry>W10=</fieldentry>

</qtimetadatafield>

</qtimetadata>

</itemmetadata>


<presentation label="titel">


<flow>


<material>

<mattext texttype="text/xhtml"><p>text1</p> <div id="OKAYFREEDOM_INJECTED" style="display: none;"></div></mattext>

</material>


<material>

<mattext texttype="text/xhtml"><p></p> <p>text2</p> <p></p> <p>auswahllücke</mattext>

</material>

Part 2 :

<response_str ident="gap_0" rcardinality="Single">


<render_choice shuffle="No">


<response_label ident="0">


<material>

<mattext>auswahl1</mattext>

</material>

</response_label>


<response_label ident="1">


<material>

<mattext>auswahl2</mattext>

</material>

</response_label>

</render_choice>

</response_str>


<material>

<mattext texttype="text/plain">textlücke</mattext>

</material>


<response_str ident="gap_1" rcardinality="Single">

<render_fib maxchars="2" columns="8" prompt="Box" fibtype="String"/>

</response_str>


<material>

<mattext texttype="text/plain">numlücke</mattext>

</material>


<response_num ident="gap_2" rcardinality="Single" numtype="Decimal">

<render_fib maxchars="3" columns="2" prompt="Box" fibtype="Decimal" maxnumber="100" minnumber="1"/>

</response_num>


<material>

<mattext texttype="text/xhtml"></p> <p></p> <div></div> <p></p> <div></div> <div></div></mattext>

</material>

</flow>

</presentation>

Part 3:

<resprocessing>


<outcomes>

<decvar/>

</outcomes>


<respcondition continue="Yes">


<conditionvar>

<varequal respident="gap_0">auswahl1</varequal>

</conditionvar>

<setvar action="Add">1</setvar>

<displayfeedback linkrefid="0_Response_0" feedbacktype="Response"/>

</respcondition>


<respcondition continue="Yes">


<conditionvar>

<varequal respident="gap_0">auswahl2</varequal>

</conditionvar>

<setvar action="Add">2</setvar>

<displayfeedback linkrefid="0_Response_1" feedbacktype="Response"/>

</respcondition>


<respcondition continue="Yes">


<conditionvar>

<varequal respident="gap_1">antwort1</varequal>

</conditionvar>

<setvar action="Add">3</setvar>

<displayfeedback linkrefid="1_Response_0" feedbacktype="Response"/>

</respcondition>


<respcondition continue="Yes">


<conditionvar>

<varequal respident="gap_1">antwort2</varequal>

</conditionvar>

<setvar action="Add">4</setvar>

<displayfeedback linkrefid="1_Response_1" feedbacktype="Response"/>

</respcondition>


<respcondition continue="Yes">


<conditionvar>

<varequal respident="gap_2">99</varequal>

</conditionvar>

<setvar action="Add">5</setvar>

<displayfeedback linkrefid="2_Response_0" feedbacktype="Response"/>

</respcondition>

Part 4:

<itemfeedback ident="response_onenotcorrect" view="All">


<flow_mat>


<material>

<mattext texttype="text/xhtml"><p>respnotcorrect</p> <div id="OKAYFREEDOM_INJECTED" style="display: none;"></div></mattext>

</material>

</flow_mat>

</itemfeedback>

The part in between I dont need, I only need this 4 parts of the xml file. How can I split this in an easy way? Some elements were named more than one time.

Patrick
  • 5
  • 2

2 Answers2

0

I would go with the XMLDocument reader/writer. You can manipulate in memory the elements you need.

Loads of documentation can be found on the subject e.g.: using xmldocument to read xml

Aldert
  • 4,209
  • 1
  • 9
  • 23
0

You only posted part 1 at you link. Below I used xml linq to get element. If the file is huge you will need to also use xmlreader

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";

        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);
            XElement resprocessing = doc.Descendants("resprocessing").FirstOrDefault();

            string header = "<?xml version=\"1.0\" encoding=\"utf-8\"?><resprocessing></resprocessing>";
            XDocument newDoc = XDocument.Parse(header);
            XElement newResprocessing = newDoc.Root;
            newResprocessing.ReplaceWith(resprocessing);
        }
    }
}
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • Sorry i edited the link now. Its quite huge. It would reach to extract part 3 from the great xml and delete the not needed parts. – Patrick Jan 19 '19 at 17:07