SQLXML Importing Attribute and Elements into same DB record

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JimP

    SQLXML Importing Attribute and Elements into same DB record

    I'm importing XML files into a SQLExpress DB using SQLXML and VB.net
    2005. I have a simple *.xsd schema file that is pulling in all
    attributes from the <Activityelemen t.

    It also has a <Headerelemen t that I'd like to add the 'Run'
    attribute for each record in the TA_HeaderID field. So, in the
    example, '879" would be added to each record in the TA_HeaderID field.

    Schema file...
    <?xml version="1.0" encoding="utf-8"?>
    <xsd:schema xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    xmlns:sql="urn: schemas-microsoft-com:mapping-schema">
    <xsd:element name="Activity" sql:relation="T erminalTable">
    <xsd:complexTyp e>
    <xsd:attribut e name="Group" sql:field="TA_G roup"
    type="xsd:strin g" use="required" />
    <xsd:attribut e name="GN" sql:field="TA_G N"
    type="xsd:unsig nedByte" use="required" />
    <xsd:attribut e name="Set" sql:field="TA_S et" type="xsd:strin g"
    use="required" />
    <xsd:attribut e name="Term" sql:field="TA_T erm" type="xsd:strin g"
    use="required" />
    <xsd:attribut e name="TN" sql:field="TA_T N"
    type="xsd:unsig nedShort" use="required" />
    </xsd:complexType >
    </xsd:element>
    </xsd:schema>

    ..XML file...
    <?xml version="1.0" ?>
    <TA>
    <Header Version="V418.0 5"Run="879"/>
    <Activity Group="DAB" GN="2" Set="W01" Term="XCTPAY" TN="512"/>
    <Activity Group="DAB" GN="2" Set="W01" Term="XGDB03" TN="523"/>
    <Activity Group="DAB" GN="2" Set="W01" Term="XGDB06" TN="526"/>
    <Activity Group="DAB" GN="2" Set="W01" Term="XGDB09" TN="1080"/>
    </TA>

    CREATE TABLE [dbo].[TA](
    [TA_HeaderID] [int] ,
    [TA_Group] [varchar](3),
    [TA_GN] [smallint] ,
    [TA_Set] [varchar](3) ,
    [TA_Term] [varchar](6) ,
    [TA_TN] [smallint] ,
    ) ON [PRIMARY]

    I tried adding the following to the schema but all this does is add
    one
    record to the DB which is not what I desire.

    <xsd:element name="Header" sql:relation="T A">
    <xsd:complexTyp e>
    <xsd:attribut e name="Run" sql:field="TA_H eaderId"
    type="xsd:strin g" use="required" />
    </xsd:complexType >
    </xsd:element>

    If I add the line
    <xsd:attribut e name="Run" sql:field="TA_H eaderId" type="xsd:strin g"
    use="required" />
    under
    '<xsd:element name="Activity" sql:relation="T erminalTable">'
    ....TA_HeaderId remains empty

    How do you edit the schema file to include this Attribute field for
    each record?
    thanks
    Jim
Working...