Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2008, 09:25 AM
Registered User
 
Join Date: May 2008
Location: , , Australia.
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!




Reply With Quote
  #2 (permalink)  
Old June 6th, 2008, 03:50 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
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
========================
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:46 AM.


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