XML

Top  Previous  Next

Sample XML to DB

 

<pdroot>

 <XmlToDb>

         <General>

                 <ConnectionName>Data Entry</ConnectionName>

                 <XMLRepository>D:\Temp</XMLRepository>

                 <XMLFileMask>*.xml</XMLFileMask>

                 <DocStartXP>.</DocStartXP>

                 <RecordListStartXP>.</RecordListStartXP>

                 <RecordItemName>Crashes</RecordItemName>

                 <RecordStartXP>.</RecordStartXP>

                 <DuplicateAction>OverwriteExisting</DuplicateAction>

         </General>

         <RowSpecs>

                 <RowSpec>

                         <Name>Collision</Name>

                         <TableName>Collisions</TableName>

                         <ListStartXP>.</ListStartXP>

                         <ItemName>.</ItemName>

                         <UniqueObjectColumnNames>

                                 <ColumnName>CaseId</ColumnName>

                         </UniqueObjectColumnNames>

                         <UniqueTableColumnNames>

                                 <ColumnName>CaseId</ColumnName>

                         </UniqueTableColumnNames>

                         <AutoRecords>

                                 <AutoRecord Name="StreetsCollection">

                                         <TableName>Streets</TableName>

                                         <Columns>

                                                 <Column Name="StreetNum" IsNextId="True"/>

                                                 <Column Name="StreetName"/>

                                         </Columns>

                                 </AutoRecord>

                         </AutoRecords>

                         <Columns>

                                 <Column>

                                         <ColumnName>CaseId</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "CaseId" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>Street1</ColumnName>

                                         <LookupMethod>AutoRecord</LookupMethod>

                                         <LookupReference>StreetsCollection</LookupReference>

                                         <ValueXPExpression Column="StreetName">impRowNodeText("Street1" )</ValueXPExpression>

                                 </Column>

                                 <Column>

                                         <ColumnName>Street2</ColumnName>

                                         <LookupMethod>AutoRecord</LookupMethod>

                                         <LookupReference>StreetsCollection</LookupReference>

                                         <ValueXPExpression Column="StreetName">impRowNodeText("Street2" )</ValueXPExpression>

                                 </Column>

                         </Columns>

                         <SubSpecNames>

                                 <SubSpecName>VehicleOne</SubSpecName>

                         </SubSpecNames>

                 </RowSpec>

         </RowSpecs>

         <SubSpecs>

                 <RowSpec>

                         <Name>VehicleOne</Name>

                         <TableName>Vehicles</TableName>

                         <DoWriteExpression>true</DoWriteExpression>

                         <ListStartXP>.</ListStartXP>

                         <ItemName>.</ItemName>

                         <UniqueObjectColumnNames>

                                 <ColumnName>CaseId</ColumnName>

                         </UniqueObjectColumnNames>

                         <UniqueTableColumnNames>

                                 <ColumnName>CaseId</ColumnName>

                                 <ColumnName>VehNum</ColumnName>

                         </UniqueTableColumnNames>

                         <AutoRecords/>

                         <Columns>

                                 <Column>

                                         <ColumnName>CaseId</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "CaseId" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>VehNum</ColumnName>

                                         <ValueXPExpression>1</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>UnitType</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "UnitType" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>TravelDirection</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "TravelDirection" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                         </Columns>

                         <SubSpecNames>

                                 <SubSpecName>PersonRecord</SubSpecName>

                         </SubSpecNames>

                 </RowSpec>

                 <RowSpec>

                         <Name>PersonRecord</Name>

                         <TableName>Person</TableName>

                         <DoWriteExpression>true</DoWriteExpression>

                         <ListStartXP>Persons</ListStartXP>

                         <ItemName>Person</ItemName>

                         <DoWriteExpression>true</DoWriteExpression>

                         <ListStartXP>.</ListStartXP>

                         <ItemName>.</ItemName>

                         <UniqueObjectColumnNames>

                                 <ColumnName>CaseId</ColumnName>

                         </UniqueObjectColumnNames>

                         <UniqueTableColumnNames>

                                 <ColumnName>CaseId</ColumnName>

                                 <ColumnName>VehNum</ColumnName>

                                 <ColumnName>PersonNumber</ColumnName>

                         </UniqueTableColumnNames>

                         <Columns>

                                 <Column>

                                         <ColumnName>CaseId</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "CaseId" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>VehNum</ColumnName>

                                         <ValueXPExpression>1</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>PersonID</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "PersonID" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>PersonNumber</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "PersonNumber" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                                 <Column>

                                         <ColumnName>PersonType</ColumnName>

                                         <ValueXPExpression>impRowNodeText( "PersonType" )</ValueXPExpression>

                                         <LookupMethod>none</LookupMethod>

                                         <LookupReference/>

                                 </Column>

                         </Columns>

                         <SubSpecNames/>

                 </RowSpec>

         </SubSpecs>

 </XmlToDb>

 <Settings/>

</pdroot>

 

 

General section - The general section is used to define the starting point of the XML document being used for Import.

 

ConnectionName: Name of the Crash Magic connection that will be used to insert records into the database.

XMLRepository: This feature has been deprecated.

XMLFileMask: Mask to read the files that are to be imported(*.xml will default to reading all .xml files uploaded.)

DocStartXP: The XPath definition of the starting point of the xml document.

RecordListStartXP: The XPath definition for the parent node to a list of child nodes(This is used for clients with multiple records in a single XML file).

RecordItemName: Child node of the node list defined in the RecordListStartXP.

RecordStartXP: XPath definition that defines the starting point for selecting records. This is the default starting point when RecordListStartXP and RecordItemName are left blank.

DuplicateAction: Action to be taken if the record already exists in the database. Options are:

Skip - Skip importing the record

OverwriteExisting - Deletes the record from the database an imports the record from the xml file

UpdateExisting -

LeaveExisting -

 

Row specification section - The Row specification section specifies a record to be imported.

 

RowSpec: Start of a record import.

Name: Name of the RowSpec.

TableName: The name of the table that records will be imported into.

DoWriteExpression: Expression that determines when a record should be written.

ListStartXP: The XPath definition of a parent node to a list of child nodes(In the Unit RowSpec the XML has a Units section with one or more Unit).

ItemName: Child node of the node list defined in ListStartXP.

UniqueObjectColumnNames: List of columns that determine a unique record.

ColumnName:The name of a column that determines a unique record.

UniqueTableColumnNames:List of unique fields of the table being imported into(Primary key fields for the table).

ColumnName: The field name of the table that determines a unique record.

 

Auto Records specification section - This section is used to maintain a list of items that will be added to. In this example  auto records are being used to maintain a list of streets from the streets table. If the street name exists in the data the Id(StreetNum field) will be imported to the record. If the street name does not exist the street will be added to the Streets table, and the Id for the new street will be imported into the Collisions table.

 

AutoRecords: Specifies the start of an auto record section

AutoRecord: The Name attribute of this element is used to name the auto record section

TableName

Columns

Column

 

 

Columns: Specifies the list of fields that data will be added to.

Column: Specifies a column that will be updated.

ColumnName: Name of the field in the table that will have data added inserted.

ValueXPEression: Expression used to define the data imported into the field.

There are two functions that can be used to retrieve values from the XML:

ImpRowNodeText(): Starts at the current XML position and retrieves a value from the XML node specified in the  function.

ImpRecordNodeText(): Starts at the RecordStartXP of an XML record. This import function is used when a SubSpec  record requires a value from a parent node.

LookupMethod: Specifies the method that should be used to lookup a value. Possible values are none, , lookup, streetnormalizer, streetnormalizerlu, and nodenormalizer.

none - No lookup in use for the column

lookup - Performs a lookup for the data provided. This causes the lookup to return an Id for a human readable value passed.

<AutoRecord attribute name>

 

LookupReference: Specifies name of the lookup field or normalizer that will be used.

 

SubSpecNames: Used to specify child records that must be imported first.

SubSpecName: Name of the child RowSpec that will be imported before the current record import.