1

I have the code below which saves a sharepoint list to xml by using dataset. Below the code you will see the output in xml format.

There are a few things which I would like some help:

  1. How can I save the data together with the data type in xml by using dataset?

Example: The result that I would like to have or something like this, so that when I read the xml file I can convert them back to the right data type

<NewDataSet>
  <Report_x0020_List>
    <Title **Type="Text"**>My title</Title>
    <RequesterID **Type="Number"**>1</RequesterID>
    <AdditionalRemarks **Type="Note"**>Additional Remarks </AdditionalRemarks>
    <DeliveryDate **Type="DateTime"**>2012-07-13T00:00:00+02:00</DeliveryDate>
    ...... and so on
  </Report_x0020_List>
</NewDataSet>

2) Right now the root of the xml file is called NewDataSet. Is there a way that I can manipulate this before it is saved as xml? I would like to have control over how the elements are named.

-----Desired result--------

<MyReportList>
   <Report>

   </Report>
</MyReportlist>

---- not like this ------

<NewDataSet>

</NewDataSet>

3) if the saving the data type is not possible can you show me good example how to convert it the data from xml string to the right type in sharepoint?


Code I am using

if($lists.List.Length -gt 0)
    {
        foreach ($list in $lists.List)
        {
            $listName = $list.Attributes.Item(0).Value

            $myList=$spweb.Lists[$listName]

            if($myList -ne $null)
            {

                 if ($myList.Items.Count -gt 0)
                {
                    $spQuery = New-Object Microsoft.SharePoint.SPQuery
                    $spQuery.Query = $query
                    #$myList.GetItems($spQuery).GetDataTable(); 
                    $dt = $myList.GetItems($spQuery).GetDataTable()


                    $ds = New-Object System.Data.DataSet
                    $ds.Tables.Add($dt)

                    $ds.WriteXml("$filePath$fileName")
                }
            }
        }

    }

The result I am getting

<NewDataSet>
  <Report_x0020_List>
    <Title>My title</Title>
    <RequesterID>1</RequesterID>
    <AdditionalRemarks>Additional Remarks </AdditionalRemarks>
    <DeliveryDate>2012-07-13T00:00:00+02:00</DeliveryDate>
    <DueDate>2012-07-14T00:00:00+02:00</DueDate>
    <Format>TXT</Format>
    <Source>;#ASTV;#BS;#</Source>
    <Frequency>Once</Frequency>
    <Hold>1</Hold>
    <MoreInformation>More qsd sgvfsdfsdf Information </MoreInformation>
    <Owner>sp_user1;#19;#sp_user2</Owner>
  </Report_x0020_List>
</NewDataSet>
4

0 回答 0