M
Markus Freitag
Guest
Hello,
I have an XML file, I copy it and paste it via the clipboard. Classes are created.
I can read the values -> IO
If I change values and save them again the namespaces are lost or look different. So how can I save it correctly? With same namespace as the original?
I found nothing in google
Thanks in advance for tips.
Greetings Markus
<?xml version="1.0"?>
<Msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="XML Schema" xmlns="http://Epicor.com/Message/2.0">
<Hdr>
<Ctrl>
<MsgID />
</Ctrl>
<Sender>
<Name />
<Subname />
</Sender>
// ##################################################################################
static T Deserialize<T>(Stream stream)
{
var serializer = new XmlSerializer(typeof(T));
using (stream)
return (T)serializer.Deserialize(stream);
}
using (var file = File.OpenRead(@"C:\Users\Freitag\Documents\TEST_M.xml"))
{
var gpx = Deserialize<Msg>(file);
var jobNo = gpx.Body.Req.Dta.Results.QueryResultDataSet.Results.JobHead_JobNum;
jobNo = 6666666;
gpx.Body.Req.Dta.Results.QueryResultDataSet.Results.JobHead_JobNum = 66663333;
var serializer = new XmlSerializer(typeof(Msg));
using (var fileWrite = File.Create(@"C:\Users\Freitag\Documents\TEST_M_NEW.xml"))
serializer.Serialize(fileWrite, gpx);
}
<?xml version="1.0" encoding="utf-16"?>
<msg:Msg xsi:schemaLocation="http://EBMThirdProducer.com/Message/2.0 http://scshost/schemas/epicor/ScalaMessage.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msg="http://EBMThirdProducer.com/Message/2.0">
<msg:Hdr>
<msg:Ctrl>
<msg:MsgID></msg:MsgID>
</msg:Ctrl>
<msg:Sender>
<msg:Name></msg:Name>
<msg:Subname></msg:Subname>
</msg:Sender>
<msg:Receiver>
<msg:Name>Company</msg:Name>
<msg:Subname>OrderData</msg:Subname>
</msg:Receiver>
<msg:Logon></msg:Logon>
</msg:Hdr>
<msg:Body>
<msg:Req msg-type="Company" action="GetOrderData">
<msgta>
<ext_UserSchema:Results xmlns:msg="http://EBMThirdProducer.com/InternalMessage/1.1" xmlns:ext_UserSchema="http://EBMThirdProducer.com/SC/UserSchema">
<QueryResultDataSet xmlns:xsd="XML Schema">
<Results>
<JobHead_JobNum>116666580</JobHead_JobNum>
<JobHead_PartNum>555724307910003</JobHead_PartNum>
<JobHead_ProdQty>5.06000000</JobHead_ProdQty>
<CustXPrt_XPartNum>33666-355-03</CustXPrt_XPartNum>
<CustXPrt_XRevisionNum>D1</CustXPrt_XRevisionNum>
<CustXPrt_SNLastUsedSeq/>
<Calculated_TemplateID>31166-355-03</Calculated_TemplateID>
</Results>
<ExecutionInfo>
<Name>ExecutionTime</Name>
<Value>77.7252</Value>
</ExecutionInfo>
</QueryResultDataSet>
</ext_UserSchema:Results>
</msgta>
</msg:Req>
</msg:Body>
</msg:Msg>
Continue reading...
I have an XML file, I copy it and paste it via the clipboard. Classes are created.
I can read the values -> IO
If I change values and save them again the namespaces are lost or look different. So how can I save it correctly? With same namespace as the original?
I found nothing in google
Thanks in advance for tips.
Greetings Markus
<?xml version="1.0"?>
<Msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="XML Schema" xmlns="http://Epicor.com/Message/2.0">
<Hdr>
<Ctrl>
<MsgID />
</Ctrl>
<Sender>
<Name />
<Subname />
</Sender>
// ##################################################################################
static T Deserialize<T>(Stream stream)
{
var serializer = new XmlSerializer(typeof(T));
using (stream)
return (T)serializer.Deserialize(stream);
}
using (var file = File.OpenRead(@"C:\Users\Freitag\Documents\TEST_M.xml"))
{
var gpx = Deserialize<Msg>(file);
var jobNo = gpx.Body.Req.Dta.Results.QueryResultDataSet.Results.JobHead_JobNum;
jobNo = 6666666;
gpx.Body.Req.Dta.Results.QueryResultDataSet.Results.JobHead_JobNum = 66663333;
var serializer = new XmlSerializer(typeof(Msg));
using (var fileWrite = File.Create(@"C:\Users\Freitag\Documents\TEST_M_NEW.xml"))
serializer.Serialize(fileWrite, gpx);
}
<?xml version="1.0" encoding="utf-16"?>
<msg:Msg xsi:schemaLocation="http://EBMThirdProducer.com/Message/2.0 http://scshost/schemas/epicor/ScalaMessage.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msg="http://EBMThirdProducer.com/Message/2.0">
<msg:Hdr>
<msg:Ctrl>
<msg:MsgID></msg:MsgID>
</msg:Ctrl>
<msg:Sender>
<msg:Name></msg:Name>
<msg:Subname></msg:Subname>
</msg:Sender>
<msg:Receiver>
<msg:Name>Company</msg:Name>
<msg:Subname>OrderData</msg:Subname>
</msg:Receiver>
<msg:Logon></msg:Logon>
</msg:Hdr>
<msg:Body>
<msg:Req msg-type="Company" action="GetOrderData">
<msgta>
<ext_UserSchema:Results xmlns:msg="http://EBMThirdProducer.com/InternalMessage/1.1" xmlns:ext_UserSchema="http://EBMThirdProducer.com/SC/UserSchema">
<QueryResultDataSet xmlns:xsd="XML Schema">
<Results>
<JobHead_JobNum>116666580</JobHead_JobNum>
<JobHead_PartNum>555724307910003</JobHead_PartNum>
<JobHead_ProdQty>5.06000000</JobHead_ProdQty>
<CustXPrt_XPartNum>33666-355-03</CustXPrt_XPartNum>
<CustXPrt_XRevisionNum>D1</CustXPrt_XRevisionNum>
<CustXPrt_SNLastUsedSeq/>
<Calculated_TemplateID>31166-355-03</Calculated_TemplateID>
</Results>
<ExecutionInfo>
<Name>ExecutionTime</Name>
<Value>77.7252</Value>
</ExecutionInfo>
</QueryResultDataSet>
</ext_UserSchema:Results>
</msgta>
</msg:Req>
</msg:Body>
</msg:Msg>
Continue reading...