Note: |
Because all inner data of an object is also written into the XML, the total XML size produced by the verbose variant of the WriteXml()
methods can become quite large. Although the routines are
optimized for speed, it can still take some time to write a complete object hierarchy to XML or instantiate a hierarchy from XML. If the amount of XML
is too much, consider using one of the Compact variants, with Compact25 as recommended format (Adapter only). You can switch to a Compact variant by passing in settings to the WriteXml() method.
Consider using Adapter if you're working with XML and performance is an issue, as Adapter has support for the more compact Compact25 format and its XML routines are more optimized as they use an XmlWriter/Reader instead of an XmlDocument. |
// [C#] StreamWriter writer = new StreamWriter("customer.XML"); string customerXml = String.Empty; customer.WriteXml(out customerXml); writer.Write(customerXml); writer.Close(); // now read it back StreamReader reader = new StreamReader("customer.XML"); string xmlFromFile = reader.ReadToEnd(); reader.Close(); CustomerEntity customerFromXml = new CustomerEntity(); customerFromXml.ReadXml(xmlFromFile);
' [VB.NET] Dim writer As New StreamWriter("customer.XML") Dim customerXml As String = String.Empty customer.WriteXml(ByRef customerXml) writer.Write(customerXml) writer.Close() ' now read it back Dim reader As New StreamReader("customer.XML") Dim xmlFromFile As String = reader.ReadToEnd() reader.Close() Dim customerFromXml As New CustomerEntity() customerFromXml.ReadXml(xmlFromFile)
// [C#] StreamWriter writer = new StreamWriter("customer.XML"); string customerXml = String.Empty; customer.WriteXml( XmlFormatAspect.Compact | XmlFormatAspect.DatesInXmlDataType | XmlFormatAspect.MLTextInCDataBlocks, out customerXml); writer.Write(customerXml); writer.Close(); // now read it back StreamReader reader = new StreamReader("customer.XML"); string xmlFromFile = reader.ReadToEnd(); reader.Close(); CustomerEntity customerFromXml = new CustomerEntity(); customerFromXml.ReadXml(xmlFromFile);
' [VB.NET] Dim writer As New StreamWriter("customer.XML") Dim customerXml As String = String.Empty customer.WriteXml( _ XmlFormatAspect.Compact Or XmlFormatAspect.DatesInXmlDataType Or XmlFormatAspect.MLTextInCDataBlocks, ByRef customerXml) writer.Write(customerXml) writer.Close() ' now read it back Dim reader As New StreamReader("customer.XML") Dim xmlFromFile As String = reader.ReadToEnd() reader.Close() Dim customerFromXml As New CustomerEntity() customerFromXml.ReadXml(xmlFromFile)
<add key="cultureNameForXmlValueConversion" value="nl-NL" />
<CustomerEntity CustomerId="CHOPS" Assembly="DALTester, Version=1.0.1479.22635, Culture=neutral, PublicKeyToken=null" Type="DALTester.CustomerEntity"> <ConcurrencyPredicateFactoryToUse Type="SD.LLBLGen.Pro.ORMSupportClasses.IConcurrencyPredicateFactory"/> ... <ObjectID Type="System.Guid">033a5969-094a-4286-9e4c-944a1fcdd914</ObjectID> <Validator Assembly="Northwind, Version=1.0.1478.30380, Culture=neutral, PublicKeyToken=null" Type="Northwind.ValidatorClasses.CustomerValidator"/> ... <Fields> <CustomerId> <CurrentValue Type="System.String">CHOPS</CurrentValue> <IsChanged Type="System.Boolean">False</IsChanged> <IsNull Type="System.Boolean">False</IsNull> </CustomerId> <CompanyName> <CurrentValue Type="System.String">Chop-suey Chinese</CurrentValue> <IsChanged Type="System.Boolean">False</IsChanged> <IsNull Type="System.Boolean">False</IsNull> </CompanyName> ... </Fields> <EntityCollectionReference PropertyName="Orders"> <Orders Assembly="Northwind, Version=1.0.1478.30380, Culture=neutral, PublicKeyToken=null" Type="Northwind.HelperClasses.EntityCollection"> <Entities> <OrderEntity OrderId="10254" Assembly="DALTester, Version=1.0.1479.22635, Culture=neutral, PublicKeyToken=null" Type="DALTester.OrderEntity"> <ConcurrencyPredicateFactoryToUse Type="SD.LLBLGen.Pro.ORMSupportClasses.IConcurrencyPredicateFactory"/> <EntityReference PropertyName="Customer"> <ProcessedObjectReference ObjectID="033a5969-094a-4286-9e4c-944a1fcdd914"/> </EntityReference> ... </OrderEntity> ... </Entities> <EntityFactoryToUse Assembly="DALTester, Version=1.0.1479.22635, Culture=neutral, PublicKeyToken=null" Type="DALTester.OrderEntityFactory"/> <AllowEdit Type="System.Boolean">True</AllowEdit> <AllowRemove Type="System.Boolean">True</AllowRemove> <Count Type="System.Int32">95</Count> <AllowNew Type="System.Boolean">True</AllowNew> <SupportsChangeNotification Type="System.Boolean">True</SupportsChangeNotification> <SupportsSorting Type="System.Boolean">False</SupportsSorting> <SupportsSearching Type="System.Boolean">True</SupportsSearching> <Validator Assembly="Unknown"/> <IsReadOnly Type="System.Boolean">False</IsReadOnly> </Orders> </EntityCollectionReference> <IsNew Type="System.Boolean">False</IsNew> <LLBLGenProEntityName Type="System.String">CustomerEntity</LLBLGenProEntityName> <IsDirty Type="System.Boolean">False</IsDirty> <EntityState Type="SD.LLBLGen.Pro.ORMSupportClasses.EntityState">Fetched</EntityState> </CustomerEntity>
<OrderDetailsEntity OrderId="10289" ProductId="3"> <EntityReference PropertyName="Products" /> <ObjectID>f08047cb4d50483c99f9937a5f77a4a5</ObjectID> <IsNew>False</IsNew> <Fields> <OrderId> <CurrentValue>10289</CurrentValue> <DbValue>10289</DbValue> <IsChanged>False</IsChanged> <IsNull>False</IsNull> </OrderId> <ProductId> <CurrentValue>3</CurrentValue> <DbValue>3</DbValue> <IsChanged>False</IsChanged> <IsNull>False</IsNull> </ProductId> ... </Fields> <EntityReference PropertyName="Orders"> <OrderEntity OrderId="10289"> <Fields> <OrderId> <CurrentValue>10289</CurrentValue> <DbValue>10289</DbValue> <IsChanged>False</IsChanged> <IsNull>False</IsNull> </OrderId> ... <OrderDate> <CurrentValue>19960826T00:00:00.0000000+02:00</CurrentValue> <DbValue>19960826T00:00:00.0000000+02:00</DbValue> <IsChanged>False</IsChanged> <IsNull>False</IsNull> </OrderDate> ... </Fields> <EntityReference PropertyName="Employees" /> <EntityCollectionReference PropertyName="OrderDetails"> <OrderDetails> <Entities> <ProcessedObjectReference ObjectID="f08047cb4d50483c99f9937a5f77a4a5" /> </Entities> <AllowNew>True</AllowNew> <EntityFactoryToUse Assembly="Northwind.Adapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Type="Northwind.Adapter.FactoryClasses.OrderDetailsEntityFactory" /> <AllowRemove>False</AllowRemove> <AllowEdit>True</AllowEdit> </OrderDetails> </EntityCollectionReference> ... <IsDirty>False</IsDirty> <EntityState>Fetched</EntityState> <SavedFieldSets /> </OrderEntity> </EntityReference> <IsDirty>False</IsDirty> <EntityState>Fetched</EntityState> <SavedFieldSets /> </OrderDetailsEntity>
<CustomerEntity ObjectID="df7c7b33-1fd2-4fe9-b3b4-ec8d00eeebed" Format="Compact25"> <CustomerId>CHOPS</CustomerId> <CompanyName>Foo Inc.</CompanyName> <ContactName>Yang Wang</ContactName> <ContactTitle>Owner</ContactTitle> <Address>Hauptstr. 29</Address> <City>Bern</City> <PostalCode>3012</PostalCode> <Country>Switserland</Country> <Phone>555-chang</Phone> <Fax>1313-chan</Fax> <Orders> <OrderEntity ObjectID="d8117794-675c-45ce-bd97-f23c22391039"> <OrderId>10746</OrderId> <CustomerId>CHOPS</CustomerId> <EmployeeId>1</EmployeeId> <OrderDate>1997-11-19T00:00:00.0000000+01:00</OrderDate> <RequiredDate>1997-12-17T00:00:00.0000000+01:00</RequiredDate> <ShippedDate>1997-11-21T00:00:00.0000000+01:00</ShippedDate> <ShipVia>3</ShipVia> <Freight>31,4300</Freight> <ShipName>Chop-suey Chinese</ShipName> <ShipAddress>Hauptstr. 31</ShipAddress> <ShipCity>Bern</ShipCity> <ShipPostalCode>3012</ShipPostalCode> <ShipCountry>Switzerland</ShipCountry> <Customer Ref="df7c7b33-1fd2-4fe9-b3b4-ec8d00eeebed" /> <NullableDateTime></NullableDateTime> <CompanyName>Foo Inc.</CompanyName> <NullableDec></NullableDec> <NulledString></NulledString> <_lps fs="AACAAA==" es="1" /> </OrderEntity> ... <OrderEntity ObjectID="80a16cd2-4dd9-4e41-aae0-5a669af76257"> <OrderId>10731</OrderId> <CustomerId>CHOPS</CustomerId> <EmployeeId>7</EmployeeId> <OrderDate>1997-11-06T00:00:00.0000000+01:00</OrderDate> <RequiredDate>1997-12-04T00:00:00.0000000+01:00</RequiredDate> <ShippedDate>1997-11-14T00:00:00.0000000+01:00</ShippedDate> <ShipVia>1</ShipVia> <Freight>96,6500</Freight> <ShipName>Chop-suey Chinese</ShipName> <ShipAddress>Hauptstr. 31</ShipAddress> <ShipCity>Bern</ShipCity> <ShipPostalCode>3012</ShipPostalCode> <ShipCountry>Switzerland</ShipCountry> <Customer Ref="df7c7b33-1fd2-4fe9-b3b4-ec8d00eeebed" /> <NullableDateTime></NullableDateTime> <CompanyName>Foo Inc.</CompanyName> <NullableDec></NullableDec> <NulledString></NulledString> <_lps fs="AACAAA==" es="1" /> </OrderEntity> <_lps f="7" /> </Orders> <_lps fs="ACAA" es="1" /> </CustomerEntity>
_lps element description for Entities
The _lps attribute fs stands for ‘Field state data’ and is a bitarray, with for each field a bit for the IsChanged flag and a bit for the IsNull flag. This bitarray is then packed to a hex string. The order is by fieldindex: the field at index 0 has the first two bits (at index 0 and 1), etc. There’s no info about IsNew and IsDirty. This is because these are redundant: IsDirty can be determined from the stateflags of all the fields, and IsNew can be determined from the attribute 'es'.
The _lps attribute es stands for ‘EntityState’ and is the numeric value of the EntityState enum for the entity.
If there are fields changed, or better: if the CurrentValue for a field is different from the DbValue value, and the DbValue isn’t null/Nothing, an entry is placed for that field in the dbv element as a child of the _lps element with the DbValue value. This saves data for the fields which aren’t changed.
If the entity has an error string set, it’s stored under the ee element as a child of the _lps element.
If there are field errors stored, they’re stored under an efes element under the _lps element and every error is stored as a sub element of efes with the key as the elementname and the errorstring as the element value.
_lps element description for EntityCollection instances
The f attribute in the _lps element of the entity collection is a bitarray with the Allow* values in this order (from index 0 upwards) AllowEdit, AllowNew, AllowRemove. At bit pos 3, the DoNotPerformAddIfPresent flag is placed.