Comments (4)
You POCO object structure must be defined as below to deserialize your xml successfully.
public class EmployeeRec1
{
[ChoXmlNodeRecordField(XPath = "@Id")]
public int Id { get; set; }
[ChoXmlNodeRecordField(XPath = "Name")]
public string Name { get; set; }
[ChoXmlNodeRecordField(XPath = "/Address/*")]
public AddressLineRec[] Address { get; set; }
}
public partial class AddressLineRec
{
[XmlAttribute(AttributeName = "Id")]
public int Id { get; set; }
[XmlText]
public string AddressLine { get; set; }
}
Hope it helps.
from choetl.
Thanks!! It works :)
I see you completly by-pass the AddressRec class, since it contains only an array of AddressLine.
But what happens if I have a more "complex" situation where there are AddressRec contains more fields (possibly other arrays) or even AddressLineRec contains other fields or array of fields
Is there any way or reason to include back AddressRec?
I tried to modify your sample to manage the following xml
<Employees>
<Employee Id='1'>
<Name>Tom</Name>
<Address>
<AddressLine Id='1'>XYZ road</AddressLine>
<AddressLine Id='2'>MiceTown</AddressLine>
<Country>United States</Country>
</Address>
</Employee>
<Employee Id='2'>
<Name>Mark</Name>
<Address>
<AddressLine Id='1'>123 street</AddressLine>
<AddressLine Id='2'>TigerCity</AddressLine>
<Country>Italy</Country>
</Address>
</Employee>
</Employees>
I understand that I can flat in some way the struct introducing a Country field in EmployeeRec
public class EmployeeRec
{
[ChoXmlNodeRecordField(XPath = "@Id")]
public int Id { get; set; }
[ChoXmlNodeRecordField(XPath = "Name")]
public string Name { get; set; }
[ChoXmlNodeRecordField(XPath = "Address/AddressLine")]
public AddressLineRec[] Address { get; set; }
[ChoXmlNodeRecordField(XPath = "Address/Country")]
public string Country { get; set; }
}
But was not able to put Country and AddressLines in a distinct class :(
sorry for "abusing" of your knowledge and patience
TIA
stefano
from choetl.
In that case, you can use the original object structure with few tweaks as below
public class EmployeeRec1
{
[ChoXmlNodeRecordField(XPath = "@Id")]
public int Id { get; set; }
[ChoXmlNodeRecordField(XPath = "Name")]
public string Name { get; set; }
[ChoXmlNodeRecordField(XPath = "/Address")]
public AddressRec Address { get; set; }
}
public partial class AddressRec
{
[XmlElement(ElementName = "AddressLine")]
public AddressLineRec[] AddressLines { get; set; }
[XmlElement(ElementName = "Country")]
public string Country { get; set; }
}
public partial class AddressLineRec
{
[XmlAttribute(AttributeName = "Id")]
public int Id { get; set; }
[XmlText]
public string AddressLine { get; set; }
}
from choetl.
Great! Thank you very much!!
I was trying to use ChoXmlNodeRecordField in the AddressRec class, and it did not work :(
from choetl.
Related Issues (20)
- dots in field names cause Json to be nested in version 1.2.1.62 - not in version 1.2.1.53 HOT 2
- System.BadImageFormatException
- ParquetWriter&Compression HOT 1
- New Parquet.Net default encoding DELTA_BINARY_PACKED is causing issues with Spark HOT 3
- ChoParquetRecordFieldConfiguration not being applied correctly on file write
- JSON, XML and YAML HOT 1
- ChoJSONReader HOT 2
- Merging nested arrays to csv when arrays are empty HOT 1
- import CSV - loading CSV file with header sample not working HOT 2
- Flatten and prefix JSON to CSV HOT 3
- Missing 'Id' CSV column in CSV file HOT 2
- .Net Standard version of ChoETL.Parquet HOT 1
- Can't find Component property in System.String object. HOT 3
- Issue with header contain dot character HOT 3
- Csv to Parquet - Nullable types HOT 1
- Display header with name and type, while reading data, objects, how to get attribute name and type (nullabale)
- ChoXmlWriter - Array item names
- BCP Incorrect condition? HOT 1
- Old Code Upgrade - Pipe Delimiter - Double Quotes Now Breaking Code HOT 4
- ChoCSVWriter - No Header Output When Using WriteFields HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from choetl.