1

I have a problem with understanding XML serialization.

In my case I have got XML files with lots of different information about property owner (address, buildings, facilities,...).

The goal is to write out specific information and integrate them into a data base. I got the tip to use serialization to generate an object structure, but the examples that I a looked at just showed how to produce a new xml file.

How can I work with serialization when I already have an existing xml file I want to filter and then generate an object structure?

Here is a snippet of the XML file:

<Z1ZRMPA SEGMENT="1" DRUCK="0" ORDER="0" VISIBLE="1" ANSPRECHPARTNER="" POSTFACHADRESSE="0" XPathTBconfig="/DEFINES/SAPMUC/EG/PARVWNODES/AG" KOPIEN="1" TITLE="Auftraggeber" ENABLED="N" COLOR="ff00ffff" XPathMailAdrs="/MAILADRESSEN/SAPMUC/AG/ADRESSE[PARNR = '16220223']" PAMAILTO="obfuscated@example.com" PAKOMMENTAR="Antrag: 18.04.2012 Glas" RESULTMAILTESTER="1" NETDOCX="J">
    <KZAEN />
    <POSNR>000000</POSNR>
    <PARVW>AG</PARVW>
    <PARNR>16220223</PARNR>
    <NAME_LIST />
    <NAME1>SVG Wohnen eG</NAME1>
    <NAME2 />
    <NAME3 />
    <NAME4 />
    <CITY1>Stuttgart</CITY1>
    <CITY2 />
    <POST_CODE1>70195</POST_CODE1>
    <POST_CODE2 />
    <STREET>Regerstr.</STREET>
    <PO_BOX />
    <HOUSE_NUM1>17</HOUSE_NUM1>
    <COUNTRY>DE</COUNTRY>
    <LANGU>D</LANGU>
    <REGION>BW</REGION>
    <DEFLT_COMM />
    <REMARK />
    <Z1ZRMTE SEGMENT="1">
      <KZAEN />
      <COMM_TYPE>TEL</COMM_TYPE>
      <FLGDEFAULT />
      <TEL_NUMBER />
      <ETL_EXTENS />
      <REMARK />
    </Z1ZRMTE>
stuartd
  • 70,509
  • 14
  • 132
  • 163
Anne Martin
  • 69
  • 1
  • 10
  • First you will want to **de**serialize the XML. – stuartd May 15 '18 at 09:15
  • Send an example of the XMl data structure. – Dev May 15 '18 at 09:15
  • I usually use [this](http://xmltocsharp.azurewebsites.net/) to get my object structure then. Deserialise the XMl to the Object I get from the website, then use the data in the object(s) created fron there on. – Dev May 15 '18 at 09:18
  • You maybe want to look into the [XmlSerializer](https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(v=vs.110).aspx). There is also sample code – Freggar May 15 '18 at 09:19
  • can [this](https://stackoverflow.com/a/364401/6144699) answer help? – PSkalka May 15 '18 at 09:20
  • The are many ways of parsing an xml. You can use Serialization, Dataset method ReadXml(), XmlReader, XmlDocument, and XDocument. The best one to use is based on the size of the xml, the amount of data you need to extract (the entire file or just portions), and the structure of the xml. Then how yhou want to use the xml like put into classes, put into datatable, put into dictionary, put into lists, put into anonymous object. – jdweng May 15 '18 at 09:20
  • You can paste **valid** XML into http://xmltocsharp.azurewebsites.net/ and it will generate clases for you. – stuartd May 15 '18 at 10:09

1 Answers1

0

Open Visual Studio, Add new Class file to your project and then.

You can copy your XML and then go to Edit > Paste Special > Paste XML as Classes and Classes will be generated.

After the classes generated you can Deserialize it using XmlSerializer.

Paras
  • 31
  • 2