Best way to create an XML file without errors, which possibilities?

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,

I have to create this XML file and send it via socket.
Only a few variable contents change.
What options do I have to create this file and fill the variables?

Idea 1,
I create a template file with placeholders and then replace them.

<location lineNo="90" statNo="20" statIdx="1" fuNo="$FuNo$" workPos="1" toolPos="$ToolPos" application="Medicine"
processName="WHITE Group" processNo="$ProcessNo$" />
</header>


I read it and replace the variable with Replace("$FuNo$", "1")

I think it works, is probably not the correct solution.

I am looking for a better and more correct solution.

I found this, this can also bring out errors.
https://www.c-sharpcorner.com/article/xml-manipulation-in-c-sharp/

Would I have to create a schema file and how to do that?
It may be, I need fewer attributes than the maximum possible.

Request

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<root>
<header eventId="2" eventName="ReceivedOrder" version="1.0" eventSwitch="A23" contentType="PlantEurope" >
<location lineNo="90" statNo="20" statIdx="1" fuNo="1" workPos="1" toolPos="21" application="Medicine"
processName="WHITE Group" processNo="277" />
</header>
<event>
<ReceivedOrder identifier="BDR AC 0101 150330 1404" typeNo="ACTBMW" typeVar="0001" typeVersion="V01"
/>
</event>
<body>
<structs/>
</body>
</root>


Response

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<root>
<header eventId="2" eventName="ReceivedOrder" version="1.0" eventSwitch="12" timeStamp="2020-06-
23T15:40:41.9555440+02:00" contentType="3" >
<location lineNo="90" statNo="20" statIdx="1" fuNo="1" workPos="1" toolPos="21" application="medicine"
processName="WHITE Group" processNo="277" />
</header>
<event>
<result returnCode="0" />
<trace/>
</event>
<body>
<items>
<item name="ProcessState" value="0" dataType="bool" />
<item name="LocationState" value="0" dataType="int" />
</items>
<values>
<item pos="1" id="ACTBMW-GQ911.9-0001" partForStation="true" state="3" />
<item pos="2" id="ACTBMW-GQ911.9-0002" partForStation="true" state="3" />
<!-- NEW: -->
<item pos="3" id="ACTBMW-GQ911.9-EMPTY3" partForStation="false" state="9" />
<item pos="4" id="ACTBMW-GQ911.9-EMPTY4" partForStation="false" state="9" />
<item pos="5" id="ACTBMW-GQ955.9-0003" partForStation="true" state="2" />
<item pos="6" id="ACTBMW-GQ955.9-0004" partForStation="true" state="0" />
</values>
</body>
</root>
Best regards Markus

Continue reading...
 
Back
Top