ich muss eine XML datei erzeugen.
bisheriger code:
string batchnr = "2005368";
string exp = "2023-07-26";
string mad = "2020-07-26";
string gtin = "06221032240262";
string workorder_code = "242040_2005368_1";
string sn = "200536810100508";
string status = "Accepted";
XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance";
XDocument xDoc = new XDocument(
new XDeclaration("1.0", "UTF-8", "no"),
new XElement("PRODUCTION_IMPORTATION",
new XAttribute(XNamespace.Xmlns + "xsi", xsiNs),
new XAttribute(xsiNs + "noNamespaceSchemaLocation", "Batch.xsd"),
new XElement("BATCH",
new XAttribute("BATCH_NUMBER", batchnr),
new XAttribute("MANUFACTURE_DATE", mad),
new XAttribute("EXPIRATION_DATE", exp),
new XElement("WORKORDER",
new XAttribute("GTIN", gtin),
new XAttribute("WORKORDER_CODE", workorder_code)
)
)
));
xDoc.Root.Add(new XElement("SERIALIZED_ITEM",
new XAttribute("SERIAL", sn),
new XAttribute("Status", status)
));
xDoc.Root.Add(new XElement("SERIALIZED_ITEM",
new XAttribute("SERIAL", sn),
new XAttribute("Status", status)
));
xDoc.Save("text.xml");
ergebnis:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<PRODUCTION_IMPORTATION xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Batch.xsd">
<BATCH BATCH_NUMBER="2005368" MANUFACTURE_DATE="2020-07-26" EXPIRATION_DATE="2023-07-26">
<WORKORDER GTIN="06221032240262" WORKORDER_CODE="242040_2005368_1" />
</BATCH>
<SERIALIZED_ITEM SERIAL="200536810100508" Status="Accepted" />
<SERIALIZED_ITEM SERIAL="200536810100508" Status="Accepted" />
</PRODUCTION_IMPORTATION>
das ist leider nur fast richtig...
die
<SERIALIZED_ITEM SERIAL="200536810100508" Status="Accepted" />
<SERIALIZED_ITEM SERIAL="200536810100508" Status="Accepted" />
sollen innerhalb des WORKORDER stehen.
wie bekomm ich die also höher in die xml rein?
das eigentliche ziel ist das:
<?xml version="1.0" encoding="utf-8"?>
<PRODUCTION_IMPORTATION xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Batch.xsd">
<BATCH BATCH_NUMBER="2005368" MANUFACTURE_DATE="2020-07-26" EXPIRATION_DATE="2023-07-26">
<WORKORDER GTIN="06221032240262" WORKORDER_CODE="242040_2005368_1">
<SERIALIZED_ITEM SERIAL="200536810100508" Status="Accepted"/>
<SERIALIZED_ITEM SERIAL="200536810100516" Status="Accepted"/>
</WORKORDER>
</BATCH>
</PRODUCTION_IMPORTATION>
mfg kala