XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: [xml-dev] merge 2 xml file in c#

I'm sorry, I can only point you in the right direction, I can't hold your hand all the way. The information you are asking for is readily available.
 
Michael Kay
http://www.saxonica.com/


From: Roy Furman [mailto:RoyF@flashnetworks.com]
Sent: 31 March 2009 11:58
To: 'Michael Kay'
Subject: RE: [xml-dev] merge 2 xml file in c#

Thank You

But I still need your help i do not understand is how to use xsl in C#

How do I transfer the directory location or any other parameters?

And how do I work with xsl so in the end I will be able to save the result into a file.

 


From: Michael Kay [mailto:mike@saxonica.com]
Sent: Tuesday, March 31, 2009 1:50 PM
To: Roy Furman; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

 

Then you're probably better off with XSLT 2.0 (which makes grouping easy). Something like

 

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

<xsl:template name="main">

<ResultsCollection

  <xsl:for-each-group select="collection('file:///c:/specific/directory/?select=*.xml;recurse=no')/*/*" group-by="@URL">

    <xsl:sort select="current-grouping-key()"/>

    <UrlResults URL="{current-grouping-key()">

      <xsl:copy-of select="current-group()/*"/>

   </UrlResults>

  </xsl:for-each-group>

</ResultsCollection>

</xsl:template>

 

</xsl:stylesheet>

 

Sorting the items in timestamp order would of course be dead easy if you used international date format rather than domestic US format.

 

Michael Kay

http://www.saxonica.com/

 


From: Roy Furman [mailto:RoyF@flashnetworks.com]
Sent: 31 March 2009 11:34
To: 'Michael Kay'; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

I need to do merge

Like I wrote in the example

If on both of the files I have <UrlResults URL="www.google.com"> I need to merge the childs

And if I have on the other file <UrlResults URL="www.cnn.com"> I need to append it to the end of the file

 


From: Michael Kay [mailto:mike@saxonica.com]
Sent: Tuesday, March 31, 2009 1:28 PM
To: Roy Furman; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

 

>I think that what you wrote will do append and this is not what I need

 

Then you need to explain the requirement better.

 

Michael Kay

http://www.saxonica.com/

 

 


From: Roy Furman [mailto:RoyF@flashnetworks.com]
Sent: 31 March 2009 11:12
To: 'Michael Kay'; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

I think that what you wrote will do append and this is not what I need

 


From: Michael Kay [mailto:mike@saxonica.com]
Sent: Tuesday, March 31, 2009 12:12 PM
To: Roy Furman; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

 

>Basically I need to take all the xml files from a specific directory and build 1 xml file

 

Try this XQuery in Saxon:

 

<wrapper>{collection('file:///c:/specific/directory/?select=*.xml;recurse=no')/*/*}</wrapper>

 

and execute it from C# like this:

 

       String q = "

<wrapper>{collection('file:///c:/specific/directory/?select=*.xml;recurse=no')/*/*}</wrapper>"

 

        Processor processor = new Processor();
        XQueryCompiler compiler = processor.NewXQueryCompiler();
        XQueryExecutable exp = compiler.Compile(q);
        XQueryEvaluator eval = exp.Load();
        Serializer qout = new Serializer();
        qout.SetOutputStream(new FileStream("testoutput.xml", FileMode.Create, FileAccess.Write));
        eval.Run(qout);

 

Michael Kay

 


From: Roy Furman [mailto:RoyF@flashnetworks.com]
Sent: 31 March 2009 09:27
To: 'Michael Kay'; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

10x

I do not know XSLT I will try to Google it

Basically I need to take all the xml files from a specific directory and build 1 xml file

Can you help me to write the program with xslt and c#?

I used dataset before but when I used the merge function the created result was not as I wanted it

 


From: Michael Kay [mailto:mike@saxonica.com]
Sent: Tuesday, March 31, 2009 11:21 AM
To: Roy Furman; xml-dev@lists.xml.org
Subject: RE: [xml-dev] merge 2 xml file in c#

 

You've left out some start tags, but I assume that's irrelevant.

 

Why would you want to program such a simple task in a low-level language?

 

It's dead easy in XSLT:

 

<ResultsCollection xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:copy-of select="document('a.xml')/*/*"/>

 <xsl:copy-of select="document('b.xml')/*/*"/>

</ResultsCollection>

 

or in XQuery

 

<ResultsCollection>{

   doc('a.xml')/*/*,

   doc('b.xml')/*/*

}</ResultsCollection>

 

and there are plenty of XSLT or XQuery processors you can invoke from your C# code.

 

Michael Kay

http://www.saxonica.com/

 


From: Roy Furman [mailto:RoyF@flashnetworks.com]
Sent: 31 March 2009 08:47
To: 'xml-dev@lists.xml.org'
Subject: [xml-dev] merge 2 xml file in c#

Hi

I am having trouble to merge this 2 files into 1 file using c#

Thanks for the help

 

File 1

<?xml version="1.0" encoding="utf-8"?>

  <UrlResults URL="www.google.com">

    <Result Iteration="1">

      <TimeStamp>3/26/2009 5:38:25 PM</TimeStamp>

    </Result>

    <Result Iteration="2">

      <TimeStamp>3/26/2009 5:43:17 PM</TimeStamp>

    </Result>

  </UrlResults>

 </ResultsCollection>

 

File 2

<?xml version="1.0" encoding="utf-8"?>

  <UrlResults URL="www.cnn.com">

    <Result Iteration="1">

      <TimeStamp>3/26/2009 9:19:55 PM</TimeStamp>

    </Result>

    <Result Iteration="2">

      <TimeStamp>3/26/2009 9:20:42 PM</TimeStamp>

    </Result>

    <Result Iteration="3">

      <TimeStamp>3/26/2009 9:21:19 PM</TimeStamp>

    </Result>

  </UrlResults>

  <UrlResults URL="www.google.com">

    <Result Iteration="1">

      <TimeStamp>3/27/2009 4:33:24 PM</TimeStamp>

    </Result>

  </UrlResults>

</ResultsCollection>

 

Result file should look

<?xml version="1.0" encoding="utf-8"?>

  <UrlResults URL="www.google.com">

    <Result Iteration="1">

      <TimeStamp>3/26/2009 5:38:25 PM</TimeStamp>

    </Result>

    <Result Iteration="2">

      <TimeStamp>3/26/2009 5:43:17 PM</TimeStamp>

    </Result>

            <Result Iteration="1">

      <TimeStamp>3/27/2009 4:33:24 PM</TimeStamp>

    </Result>

  </UrlResults>

  <UrlResults URL="www.cnn.com">

    <Result Iteration="1">

      <TimeStamp>3/26/2009 9:19:55 PM</TimeStamp>

    </Result>

    <Result Iteration="2">

      <TimeStamp>3/26/2009 9:20:42 PM</TimeStamp>

    </Result>

    <Result Iteration="3">

      <TimeStamp>3/26/2009 9:21:19 PM</TimeStamp>

    </Result>

  </UrlResults>

 </ResultsCollection>

 

 

 

 



This mail was sent via Mail-SeCure System.



This mail was sent via Mail-SeCure System.



This mail was sent via Mail-SeCure System.



This mail was sent via Mail-SeCure System.



This mail was sent via Mail-SeCure System.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS