Re: Xml back to Dataset?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Well there is also a change in 'standalone' attribute - maybe it has
something to do with the problem? The other guess would be that there is an
unicode preamble before <?xml tag and it may cause problems. Check memory
view of the string.

Peter

"Carl" <ask4it> wrote in message
news:%23fZCHJCcFHA.2420@xxxxxxxxxxxxxxxxxxxxxxx
> Thanks for Your answer.
>
> The dataset has only one table, it looks like this when saved to Xml:
>
> <?xml version="1.0" standalone="yes"?>
> <NewDataSet>
> <Document>
> <id>1</id>
> <Type>aType</Type>
> <Name>aName</Name>
> <Date>2005-06-03T00:00:00.0000000+02:00</Date>
> <Text>some text</Text>
> </Document>
> </NewDataSet>
>
> The only change I make (in Word) is to the Type value (change to some
> other text). It all comes back to VS in good shape, looking like this:
>
> <?xml version="1.0" standalone="no"?>
> <NewDataSet>
> <Document>
> <id>1</id>
> <Type>Changed value here</Type>
> <Name>aName</Name>
> <Date>2005-06-03T00:00:00.0000000+02:00</Date>
> <Text>some text</Text>
> </Document>
> </NewDataSet>
>
> regards
>
> Carl
>
> "Sahil Malik [MVP]" <contactmethrumyblog@xxxxxxxxxx> wrote in message
> news:%23kVqa%23AcFHA.3840@xxxxxxxxxxxxxxxxxxxxxxx
>> Carl,
>>
>> How many datatables does your dataset have? Also the changes that you are
>> making - what table are they in? (First table? Second table?)
>>
>> - Sahil Malik [MVP]
>> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
>> ----------------------------------------------------------------------------
>>
>> "Carl" <ask4it> wrote in message
>> news:uFPFxzAcFHA.220@xxxxxxxxxxxxxxxxxxxxxxx
>>> Hi
>>>
>>> I've tried lots of different ways to get this example to work, but
>>> nothing seems to happen.
>>>
>>> I have a Dataset in a winform. I take one record in the dataset and
>>> convert it to Xml with the WriteXml method. This works fine.
>>>
>>> Then I export it to Word, do a minor change to it (using the Xml-tools
>>> for Word), and hook up the BeforeSave event. This also works fine.
>>>
>>> When the code in the event starts to execute, I get the Xml-code back, I
>>> can see that it is changed when I inspect it. Good.
>>>
>>> Now, to get it into a dataset, and update it to the backend db seems
>>> virtually impossible. In the code below, two of all of my trials are
>>> present (one is commented out). Exceptions are never raised, it just
>>> does not do anything! I would be very happy if someone could point out
>>> what I'm doing wrong!
>>>
>>> Generate the Xml to send to Word:
>>>
>>> private void GenerateXML_Click(object sender, EventArgs e)
>>> {
>>> //testDataSet tds = new testDataSet();
>>>
>>> DataTable dt = documentTableAdapter.GetDocumentById(1);
>>> DataSet ds = new DataSet();
>>> ds.Tables.Add(dt);
>>>
>>> StringWriter sw = new StringWriter();
>>> ds.WriteXml(sw, XmlWriteMode.DiffGram);
>>> xmlDoc = sw.ToString();
>>> if (! File.Exists(xmlFileName))
>>> {
>>> ds.WriteXml(xmlDoc, XmlWriteMode.DiffGram);
>>> }
>>>
>>> if (!File.Exists(xmlSchemaName))
>>> {
>>> ds.WriteXmlSchema(xmlSchemaName);
>>> }
>>> }
>>>
>>> Send it to Word:
>>>
>>> private void btSendToWord_Click(object sender, EventArgs e)
>>> {
>>> Word.ApplicationClass wordApp = new Word.ApplicationClass();
>>> wordApp.Visible = true;
>>> Word.Document doc = wordApp.Documents.Add(ref missing, ref
>>> missing, ref missing, ref missing);
>>>
>>> Object aliasObj = "XmlTestSchema";
>>> Object namespaceUriObj = "http://www.w3.org/2001/XMLSchema";;
>>> Word.XMLNamespace schema =
>>> wordApp.XMLNamespaces.Add("c:\\Temp\\XmlTest\\XmlTestSchema.xsd", ref
>>> namespaceUriObj, ref aliasObj, false);
>>> Object obj = doc;
>>> schema.AttachToDocument(ref obj);
>>>
>>> Word.Range range = doc.Range(ref missing, ref missing);
>>> range.InsertXML(xmlDoc, ref missing);
>>>
>>> wordApp.DocumentBeforeSave += new
>>> Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(wordApp_DocumentBeforeSave);
>>> }
>>>
>>> Try to get it back, this is probably where the problem is:
>>>
>>> void
>>> wordApp_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc,
>>> ref bool SaveAsUI, ref bool Cancel)
>>> {
>>> string xmlReturn = Doc.Range(ref missing, ref
>>> missing).get_XML(true);
>>> System.Diagnostics.Debug.Write(xmlReturn);
>>>
>>> //DataSet ds = new DataSet();
>>> //ds.ReadXml(new StringReader(xmlReturn),
>>> XmlReadMode.InferSchema);
>>>
>>> testDataSet.ReadXml(new StringReader(xmlReturn),
>>> XmlReadMode.DiffGram);
>>> //testDataSet.Merge(ds, true,
>>> MissingSchemaAction.AddWithKey);
>>>
>>> documentTableAdapter.Update(testDataSet);
>>> }
>>>
>>> regards
>>>
>>> Carl
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: Xml back to Dataset?
    ... the rowstates should not change - which is why it ... Load the resultant XML in a different dataset, ... >> Carl, ... >>> ref bool SaveAsUI, ref bool Cancel) ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Deleting data in dataset
    ... Best regards, ... I have a dataset loaded from an XML file. ... // Upload Link Data. ... dr is the datarow from the dataset. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: FOR XML AUTO, ELEMENTS
    ... correct line length and that stream blocks were automatically appended as ... The reason why I said 4000 is that each stream ... > But regardless of the setting, if you get the XML in more than one chunk ... > Best regards ...
    (microsoft.public.sqlserver.xml)
  • RE: SP1 Problem SOAPException doesnt return quote and Umlaute correcty
    ... I went through the XML 1.0 Specs and it is correct XML as such. ... Thanks & Regards ... Our web service was working fine until we installed .net Framework 1.1 ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: DataSet Losing Data when Column Name Contains Colon
    ... Microsoft should've fixed this by now since they know about ... > before writing the xml, and before reading it - then just change them back ... > Hope this one does help, apologies again for the last post:) ... >> Regards. ...
    (microsoft.public.dotnet.framework.adonet)