Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem merge XML documents with whitespace

Status
Not open for further replies.

nakkii

Programmer
Jul 11, 2002
38
0
0
US
Here is my code:

____________________________________________________
Imports System.Xml
Module XMLMerge

Sub MergeXML(ByVal XMLPath As String, ByVal XMLFile1 As String, ByVal XMLFile2 As String, ByVal XMLFile3 As String)

Dim xmlreader1 As New XmlTextReader(XMLPath & XMLFile1)
Dim xmlreader2 As New XmlTextReader(XMLPath & XMLFile2)
Dim xmlreader3 As New XmlTextReader(XMLPath & XMLFile3)

Dim ds1 As New DataSet()
Try
ds1.ReadXml(xmlreader1)

Dim ds2 As New DataSet()
ds2.ReadXml(xmlreader2)

Dim ds3 As New DataSet()
ds3.ReadXml(xmlreader3)

ds1.Merge(ds2)
ds1.Merge(ds3)
ds1.WriteXml(XMLPath & "FinalFile.XML", XmlWriteMode.IgnoreSchema)
Console.WriteLine("Completed merging XML documents")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.Read()

End Sub

End Module
___________________________________________________

The resulting XML file is read by another application and uses the data to fill out a form. In this XML file are several elements that relate to checkboxes on the form.

XMLFile1:
<?xml version=&quot;1.0&quot; ?>
<Form>
<FormData FieldName=&quot;CheckBox1&quot;>X</FormData>
<FormData FieldName=&quot;CheckBox2&quot;>X</FormData>
<FormData FieldName=&quot;Checkbox3&quot;> </FormData>
</Form>

XMLFile2:
<?xml version=&quot;1.0&quot; ?>
<Form>
<FormData FieldName=&quot;CheckBox4&quot;>X</FormData>
<FormData FieldName=&quot;CheckBox5&quot;> </FormData>
<FormData FieldName=&quot;Checkbox6&quot;>X</FormData>
</Form>

When I merge the documents this is the result:

<?xml version=&quot;1.0&quot; ?>
<Form>
<FormData FieldName=&quot;CheckBox1&quot;>X</FormData>
<FormData FieldName=&quot;CheckBox2&quot;>X</FormData>
<FormData FieldName=&quot;Checkbox3&quot; />
<FormData FieldName=&quot;CheckBox4&quot;>X</FormData>
<FormData FieldName=&quot;CheckBox5&quot; />
<FormData FieldName=&quot;Checkbox6&quot;>X</FormData>
</Form>


I need to preserve the whitespace in the elements in order to clear the checkbox if it is already checked.

I have tried using the { xml:space = &quot;preserve&quot; } Tag


Please Help......


Persistence....Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. -Calvin Coolidge


Persistence....Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. -Calvin Coolidge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top