I have got 2 XML documents, both of which conform to the same XSD Schema,
which define possible optional elements. The 2 XML documents contain 2
disjoint set of XML elements.

What is the best, easiest, most efficient way of merging the 2 XML
Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any
pre-requisites?

Any other suggestions?

Re: Merging XML Documents (with ADO.NET?) by Adrian

Adrian
Wed May 25 10:50:16 CDT 2005

Patrick,

Can you provide an example of each XML document? Its not clear to me how
the schema can be the same if each XML document has different sets of XML
elements.

Also, you didn't indicate what you wanted to do after merging the XML
documents. By mentioning a DataSet, I assume you want to work with the
combined data in tables and views.

The simplest suggestion I have, without more info, is to simply concatenate
remove the root tag of one XML document and append the fragment to the other
XML document.

Ad.

"Patrick" <questions@newsgroup.nospam> wrote in message
news:9B72139F-EB53-4285-9F25-D844BFE0EBA3@microsoft.com...
>I have got 2 XML documents, both of which conform to the same XSD Schema,
> which define possible optional elements. The 2 XML documents contain 2
> disjoint set of XML elements.
>
> What is the best, easiest, most efficient way of merging the 2 XML
> Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any
> pre-requisites?
>
> Any other suggestions?



Re: Merging XML Documents (with ADO.NET?) by questions

questions
Wed May 25 11:56:03 CDT 2005

Example XML documents are:
<!--Start First XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
<?xml version="1.0" encoding="UTF-8"?>
<FormDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Forms.xsd">
<FormName FormTypeAttrib="Country">Form A</FormName>
<FormTitle>Static Form Title</FormTitle>
</FormDefinition>
<!--end First XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->

<!--Start Second XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
<?xml version="1.0" encoding="UTF-8"?>
<FormDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Forms.xsd">
<UserDescription InputType="TextArea" ReadFromDB="true">This is what the
user can fill in</UserDescription>
<SignOffs>
<Staus InputType="DropDownList" ReadFromDB="true"/>
<Comment InputType="TextArea" ReadFromDB="true"/>
</SignOffs>
</FormDefinition>
<!--End First XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->

They can share the same XSD Schema because the XSD elements are defined as
optional! After I merge the XML documents, I intend to iterate through it
and based on the attributes, etc. render an ASP.NET webform. What is the
best way of merging them?

"Adrian Moore" wrote:

> Patrick,
>
> Can you provide an example of each XML document? Its not clear to me how
> the schema can be the same if each XML document has different sets of XML
> elements.
>
> Also, you didn't indicate what you wanted to do after merging the XML
> documents. By mentioning a DataSet, I assume you want to work with the
> combined data in tables and views.
>
> The simplest suggestion I have, without more info, is to simply concatenate
> remove the root tag of one XML document and append the fragment to the other
> XML document.
>
> Ad.
>
> "Patrick" <questions@newsgroup.nospam> wrote in message
> news:9B72139F-EB53-4285-9F25-D844BFE0EBA3@microsoft.com...
> >I have got 2 XML documents, both of which conform to the same XSD Schema,
> > which define possible optional elements. The 2 XML documents contain 2
> > disjoint set of XML elements.
> >
> > What is the best, easiest, most efficient way of merging the 2 XML
> > Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any
> > pre-requisites?
> >
> > Any other suggestions?
>
>
>

Re: Merging XML Documents (with ADO.NET?) by Sahil

Sahil
Wed May 25 17:23:29 CDT 2005

Not al XSD's qualify to be a dataset. If indeed your XSD does qualifies to
be a dataset, then you can use dataset.merge, after ReadXmlSchema.

Otherwise, the best way to merge is using the XmlDocument.

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/



"Patrick" <questions@newsgroup.nospam> wrote in message
news:9B72139F-EB53-4285-9F25-D844BFE0EBA3@microsoft.com...
> I have got 2 XML documents, both of which conform to the same XSD Schema,
> which define possible optional elements. The 2 XML documents contain 2
> disjoint set of XML elements.
>
> What is the best, easiest, most efficient way of merging the 2 XML
> Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any
> pre-requisites?
>
> Any other suggestions?



Re: Merging XML Documents (with ADO.NET?) by v-kevy

v-kevy
Wed May 25 21:33:54 CDT 2005

Hi Patrick,

I agree with Sahil that only an Xml which is qualified to be a DataSet can
be loaded to a DataSet object and merged by DataSet.merge. From the Xml
snippet you have posted, I suggest you load them to an XmlDocument and
merge them in the XmlDocument.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Re: Merging XML Documents (with ADO.NET?) by questions

questions
Thu May 26 04:27:10 CDT 2005

You mean take all the child-nodes from the second XML Document and add it as
children to root nodes of the first?. I suppose whether the ordering
matters, then there are no better way other than to add an "id" attribute to
all XML elements from both XMLDocuments, and then invoke
System.Xml.XmlDocument.GetElementsById to re-order the XML nodes?

"Kevin Yu [MSFT]" wrote:

> Hi Patrick,
>
> I agree with Sahil that only an Xml which is qualified to be a DataSet can
> be loaded to a DataSet object and merged by DataSet.merge. From the Xml
> snippet you have posted, I suggest you load them to an XmlDocument and
> merge them in the XmlDocument.
>
> HTH.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>


"Patrick" wrote:

> Example XML documents are:
> <!--Start First XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
> <?xml version="1.0" encoding="UTF-8"?>
> <FormDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="Forms.xsd">
> <FormName FormTypeAttrib="Country">Form A</FormName>
> <FormTitle>Static Form Title</FormTitle>
> </FormDefinition>
> <!--end First XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
>
> <!--Start Second XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
> <?xml version="1.0" encoding="UTF-8"?>
> <FormDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="Forms.xsd">
> <UserDescription InputType="TextArea" ReadFromDB="true">This is what the
> user can fill in</UserDescription>
> <SignOffs>
> <Staus InputType="DropDownList" ReadFromDB="true"/>
> <Comment InputType="TextArea" ReadFromDB="true"/>
> </SignOffs>
> </FormDefinition>
> <!--End First XML Document!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
>
> They can share the same XSD Schema because the XSD elements are defined as
> optional! After I merge the XML documents, I intend to iterate through it
> and based on the attributes, etc. render an ASP.NET webform. What is the
> best way of merging them?
>
> "Adrian Moore" wrote:
>
> > Patrick,
> >
> > Can you provide an example of each XML document? Its not clear to me how
> > the schema can be the same if each XML document has different sets of XML
> > elements.
> >
> > Also, you didn't indicate what you wanted to do after merging the XML
> > documents. By mentioning a DataSet, I assume you want to work with the
> > combined data in tables and views.
> >
> > The simplest suggestion I have, without more info, is to simply concatenate
> > remove the root tag of one XML document and append the fragment to the other
> > XML document.
> >
> > Ad.
> >
> > "Patrick" <questions@newsgroup.nospam> wrote in message
> > news:9B72139F-EB53-4285-9F25-D844BFE0EBA3@microsoft.com...
> > >I have got 2 XML documents, both of which conform to the same XSD Schema,
> > > which define possible optional elements. The 2 XML documents contain 2
> > > disjoint set of XML elements.
> > >
> > > What is the best, easiest, most efficient way of merging the 2 XML
> > > Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any
> > > pre-requisites?
> > >
> > > Any other suggestions?
> >
> >
> >

Re: Merging XML Documents (with ADO.NET?) by v-kevy

v-kevy
Fri May 27 01:21:55 CDT 2005

Hi Patrick,

The XmlDocument doesn't care about the order of data. If you really need to
merge the two documents with order, you have to add an ID just as you
mentioned.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."