Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:39:56+00:00 2026-05-29T17:39:56+00:00

I am trying to de-serialize the following XML file. <?xml version=1.0 encoding=UTF-8?> <searchResult> <pagination>

  • 0

I am trying to de-serialize the following XML file.

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

<searchResult>

<pagination>
    <itemsPerPage>{Number of Inventories per Page}</itemsPerPage>
    <numberOfItems>{Number of Inventories}</numberOfItems>
</pagination>

<itemList>
    <item>
        {Requested Salesforce fields e.g:}
        <Id>{Salesforce Id}</Id>
        <Name>{Name}</Name>
        <pb__IsForSale__c>{e.g.}false</pb__IsForSale__c>
        <pb__IsForLease__c>{e.g.}true</pb__IsForLease__c>
        <pb__ItemDescription__c>{Item Description}</pb__ItemDescription__c>
        <pb__PurchaseListPrice__c>{Item List Price e.g.:}2000000.00</pb__PurchaseListPrice__c>
        <CurrencyIsoCode>{Currency Iso Code e.g:}EUR</CurrencyIsoCode>
        <pb__UnitBedrooms__c>{Number of Bedrooms}</pb__UnitBedrooms__c>

        <asset>
            <Id>{internal Propertybase InventoryAsset Id}</Id>
            <category>{Images, Videos or Documents}</category>
            <isExternalLink>false</isExternalLink>
            <title>{title}</title>
            <filename>{original name of the uploaded file}</filename>
            <url>{full url to image/video/document}</url>
            <thumbnailUrl>{full url to thumbnail image}</thumbnailUrl>
            <midresUrl>{full url to thumbnail image}</midresUrl>
            <tags>{comma separated tags}</tags>
            <mimeType>{e.g. image/jpeg}</mimeType>
        </asset>

        <asset>
            <Id>{internal Propertybase InventoryAsset Id}</Id>
            <category>{Images, Videos or Documents}</category>
            <isExternalLink>true</isExternalLink>
            <title>{title}</title>
            <url>{full url to image/video/document}</url>
            <tags>{comma separated tags}</tags>
        </asset>

        <asset>
           {...}
        </asset>
        {more assets ...}

    </item>

    <item>
        {...}
    </item>
    {more items ...}

</itemList>

but when I try to de-serialize it using the following code and classes

[XmlRoot("searchResult")]
public class searchResult
{
    public page pagination;
    public item[] itemList;
}

public class page
{
    public string itemsPerPage;
    public string numberOfItems;
}
public class item
{
    public string Id;
    public string Name;
    public string pb__IsForSale__c;
    public string pb__IsForLease__c;
    public string pb__ItemDescription__c;
    public string pb__PurchaseListPrice__c;
    public string CurrencyIsoCode;
    public string pb__UnitBedrooms__c;
    public string pb__TotalAreaSqft__c;
    public string pb__UnitType__c;
    [XmlElement("asset")]
    public asset[] externalDocs;
}
public class asset
{
    public string id;
    public string category;
    public string isExternalLink;
    public string title;
    public string filename;
    public string url;
    public string thumbnailUrl;
    public string midresUrl;
    public string tags;
    public string mimeType;
}

below is the de-serialization code

    public void ReadPO(string filename)
{
    // Create an instance of the XmlSerializer class;
    // specify the type of object to be deserialized.
    XmlSerializer serializer = new XmlSerializer(typeof(searchResult));

    /* If the XML document has been altered with unknown 
    nodes or attributes, handle them with the 
    UnknownNode and UnknownAttribute events.*/
    serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode);
    serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);

    // A FileStream is needed to read the XML document.
    FileStream fs = new FileStream(filename, FileMode.Open);

    // Declare an object variable of the type to be deserialized.
    searchResult po;

    /* Use the Deserialize method to restore the object's state with
    data from the XML document. */
    po = (searchResult)serializer.Deserialize(fs);

    page dppage = po.pagination;
    item[] dpitems = po.itemList;
    foreach (item itemProp in dpitems)
    {
        asset[] extImage = itemProp.externalDocs;
        foreach (asset link in extImage)
        {
            SqlConnection conninsert = new SqlConnection();
            conninsert.ConnectionString = "Data Source=MAMOOR-5E14351F; Database=elysian_RealEstateDB; User Id=sa; Password=bhomes";
            SqlCommand cmdinsert = new SqlCommand("Insert Into testtable2(column1, column2, column3, column4, column5, column6, column7, column8, column9 ,column10) Values (@Id, @Category, @isExt, @Title, @FilName, @Url, @Thumb, @MidRes, @Tag, @mimeType)", conninsert);
            cmdinsert.Parameters.Add(new SqlParameter((@"Id"), SqlDbType.NVarChar) { Value = link.id });
            cmdinsert.Parameters.Add(new SqlParameter((@"Category"), SqlDbType.NVarChar) { Value = link.category });
            cmdinsert.Parameters.Add(new SqlParameter((@"isExt"), SqlDbType.NVarChar) { Value = link.isExternalLink });
            cmdinsert.Parameters.Add(new SqlParameter((@"Title"), SqlDbType.NVarChar) { Value = link.title });
            cmdinsert.Parameters.Add(new SqlParameter((@"FilName"), SqlDbType.NVarChar) { Value = link.filename });
            cmdinsert.Parameters.Add(new SqlParameter((@"Url"), SqlDbType.NVarChar) { Value = link.url });
            cmdinsert.Parameters.Add(new SqlParameter((@"Thumb"), SqlDbType.NVarChar) { Value = link.thumbnailUrl });
            cmdinsert.Parameters.Add(new SqlParameter((@"MidRes"), SqlDbType.NVarChar) { Value = link.midresUrl });
            cmdinsert.Parameters.Add(new SqlParameter((@"Tag"), SqlDbType.NVarChar) { Value = link.tags });
            cmdinsert.Parameters.Add(new SqlParameter((@"mimeType"), SqlDbType.NVarChar) { Value = link.mimeType });
            conninsert.Open();
            cmdinsert.ExecuteNonQuery();
            conninsert.Close();
            conninsert.Dispose();
        }
    }
}

but it gives the error

tring or binary data would be truncated.
The statement has been terminated.

Description: An unhandled exception occurred during
the execution of the current web request.
Please review the stack trace for more information
about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException:
String or binary data would be truncated.
The statement has been terminated.

and when I change the the datatype of one of the variables in the mentioned classes it then gives the error of

"Input string was not in a correct format."

I can’t figure out what am I doing wrong 🙁

EDIT: when I try to de-serialize the following file, it gives all the above error

<?xml version="1.0"?>
<searchResult>
  <pagination>
    <itemsPerPage>100</itemsPerPage>
    <numberOfItems>510</numberOfItems>
  </pagination>
  <itemList>
    <item>
      <Id>askldfasdklf</Id>
      <Name>asdfasdfa</Name>
      <pb__IsForSale__c>true</pb__IsForSale__c>
      <pb__IsForLease__c>false</pb__IsForLease__c>
      <pb__ItemDescription__c>asdfasdfasdf</pb__ItemDescription__c>
      <pb__PurchaseListPrice__c>220000.00</pb__PurchaseListPrice__c>
      <CurrencyIsoCode>UAE Dirham</CurrencyIsoCode>
      <pb__UnitBedrooms__c>asdfasdf</pb__UnitBedrooms__c>
      <pb__TotalAreaSqft__c>513.00</pb__TotalAreaSqft__c>
      <pb__UnitType__c>Apartment</pb__UnitType__c>
      <asset>
        <id>asdfasdfa</id>
        <category>asdfasdf</category>
        <isExternalLink>false</isExternalLink>
        <title>external video</title>
        <filename>1.jpg</filename>
        <url>asdfasdfadf</url>
        <thumbnailUrl>asdfasdfasdf</thumbnailUrl>
        <midresUrl>asdfasdfa</midresUrl>
        <tags>
        </tags>
        <mimeType>image/jpeg</mimeType>
      </asset>
    </item>
  </itemList>
</searchResult>

while when I try to de-serialize the following file it gives no error and works fine, both the files are of the same nodes with the same format except the explicit encoding definition.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:40:00+00:00Added an answer on May 29, 2026 at 5:40 pm

    The System.Data.SqlClient.SqlException with the message “String or binary data would be truncated” means that the size of one of the columns in the table you are inserting to is too small.

    For example, if the Title column in the database has a size of 255 characters but the contents of the <title> element in the XML document is more than 255 characters, SQL Server will raise this error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to deserialize the following XML document: <?xml version=1.0 encoding=utf-8 ?> <TestPrice> <Price>
I'm trying to deserialize the following XML output: <?xml version=1.0 encoding=ISO-8859-1?> <Foo> <Val>Data1</Val> </Foo>
I'm trying to serialize an object to XML that has a number of properties,
I am trying to serialize an xml to a class with the following way:
i am trying to XML serialize a class object but having the following problem:
I'm trying to figure out how to serialize the following class into XML (in
I am trying to deserialize the following xml structure into an object... <?xml version=1.0
I'm trying to serialize a Type object in the following way: Type myType =
I am having following peice of code ,where in i am trying to serialize
i'm trying to serialize DataTable to Json or XML. is it possibly and how?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.