Re: Xml back to Dataset?
- From: "Rogas69" <rogas69@xxxxxxxxxxxxxxxx>
- Date: Mon, 13 Jun 2005 15:25:53 +0100
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
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: Xml back to Dataset?
- From: Carl
- Re: Xml back to Dataset?
- References:
- Xml back to Dataset?
- From: Carl
- Re: Xml back to Dataset?
- From: Sahil Malik [MVP]
- Re: Xml back to Dataset?
- From: Carl
- Xml back to Dataset?
- Prev by Date: Re: Oracle Blob 4000byte limitation
- Next by Date: Re: Xml back to Dataset?
- Previous by thread: Re: Xml back to Dataset?
- Next by thread: Re: Xml back to Dataset?
- Index(es):
Relevant Pages
|