Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2008, 09:25 AM
Registered User
 
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Mike250
Default Dealing with the presence of an XML tag rather tha

I'm having a head banging moment where I am sure the answer is painfully obvious but I just can't seem to get there. First, some context:

Retail Transaction log in XML being sucked into an SQL Server 2005 database. At it's simplest the TLog looks something like:

Code:
<PointOfSale>
  <Contents>
    <TLOG>
      <Transactions>
        <Transaction>
          <Items>
         ...
          </Items>
      <Tenders>
        ...
      </Tenders>
      <Customer>
        ...
      </Customer>
        </Transaction>
      </Transactions>
    </TLOG>
  </Contents>
</PointOfSale>
Following I have a code snippet to check starting at an expected node and building what is my transaction header table; essentially specific information pertaining to the transaction. I'm not having any problems doing this when the start and end tags each have data within them.


Code:
DECLARE @iDoc INT
DECLARE @xmlDoc XML
SET @xmlDoc = (SELECT * FROM OPENROWSET ( BULK 'C:\tlog.xml', SINGLE_CLOB ) AS xmlData)

--Prepare the XML Document by executing a system stored procedure
EXEC SP_XML_PREPAREDOCUMENT @iDoc OUTPUT, @xmlDoc
-- INSERT stmt for header table
INSERT INTO [Header_Table]
(
    [Type],TrxID,Date,Register,[User],Store,Charges,Taxes,Tenders,CustID,LName,FName
) 
-- SELECT stmt using OPENXML rowset provider
SELECT * FROM OPENXML (@iDoc, '/PointOfSale/Contents/TLOG/Transactions/Transaction',2)
    WITH    ([Type] VARCHAR(6),
            [GUID] VARCHAR(25),
            Date DATETIME,
            RegisterCode VARCHAR(6),
            [User] BIGINT,
            StoreUID VARCHAR(6),
            Charges MONEY,
            Taxes MONEY,
            Tenders MONEY,
            SyncID VARCHAR(25) 'Customer/SyncID',
            NameLast VARCHAR(25) 'Customer/NameLast',
            NameFirst VARCHAR(25) 'Customer/NameFirst'
            )
WHERE NOT EXISTS (SELECT * FROM [Header_Table] WHERE TrxID = [GUID])
-- Free up the memory used by the XML document.
EXEC SP_XML_REMOVEDOCUMENT @iDoc


My problem starts when I have tags with no data; in fact ending tags with no start tags and no data. It looks like this:

Code:
...
      <IsPostVoid />
        <Transaction>
          <Items>
         ...
          </Items>
      <Tenders>
        ...
      </Tenders>
      <Customer>
        ...
      </Customer>
        </Transaction>
...
The presence of the tag <IsPostVoid /> denotes this is a void transaction, so I need to record into some field the transaction "Mode" if you like. I'll create a new field on my [Header_Table] and call it Mode and would like to store in this field the word "Post Void" if <IsPostVoid /> exists in a transaction.

I'm stumped though. Ideas? Thank you in advance!




 
Old June 6th, 2008, 03:50 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Did you get this solved? I can take a look at it for you if you'd like...

========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform xml to xml changing one tag. surfer97301 XSLT 2 April 21st, 2010 05:14 PM
xml tag position change rajesh_css XSLT 1 November 3rd, 2008 04:25 AM
how to get xml tag name project2n5e0o1 Ajax 1 December 15th, 2006 09:51 AM
check presence of <?xml version="1.0"> sonhir XSLT 2 June 8th, 2006 04:54 PM
XML to (different <tag>) XML mapping Thodoris XML 4 April 27th, 2004 04:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.