Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 Display Modes
  #1 (permalink)  
Old April 26th, 2004, 10:28 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML to (different <tag>) XML mapping

I have extracted into XML formatted file a Recordset from an SQL DB and I would like to change the <tags> in this xml file. Any ideas?!

Regards,
Theodore.

Reply With Quote
  #2 (permalink)  
Old April 26th, 2004, 12:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Use MSXML2 DOM objects to access each nodes. I believe you can change the field names. Don't know the exact objects to do this, but look at both the node and element objects in the SDK.

Brian
Reply With Quote
  #3 (permalink)  
Old April 27th, 2004, 04:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Theodore,

I assume this is a continuation of your posts yesterday regarding how to get XML out of SQL Server?

If you want different tag names I see 4 options:
1. use XSLT to transform your current XML into the format you want
2. do as Brian says and use the DOM object to go through the XML one node at a time creating a new DOM object as you go with the tag names you want
3. change your SQL query to a FOR XML query and use field aliases to get the tag names you want
4. use a "standard" SQL query but instead of using the rs.Save method, go through the recordset one row at a time and use a new XML DOM to create XML from the recordset with the tag names you need

Personally I would go with 1 or 3 depending on what XML you have and what XML you need...

hth
Phil
Reply With Quote
  #4 (permalink)  
Old April 27th, 2004, 04:55 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian,
The use of MSXML2 objects solved the problem. The code follows:


Dim XmlXSLTFile
Dim XmlSrcFile
Dim XmlOutFile

' file names
XmlXSLTFile = "F:\thodoris\Work\books.xsl"
XmlSrcFile = "F:\thodoris\Work\books.xml"
XmlOutFile = "F:\thodoris\Work\\booksOUT.xml"

' load XSLT (in memory)
Dim XmlXSLT
Set XmlXSLT = CreateObject("MSXML2.DOMDocument.4.0")
XmlXSLT.Load (XmlXSLTFile)

' load source XML document file (in memory)
Dim XmlDoc
Set XmlDoc = CreateObject("MSXML2.DOMDocument.4.0")
XmlDoc.Load (XmlSrcFile)

' create new empty output (in memory) document
Dim XmlOut
Set XmlOut = CreateObject("MSXML2.DOMDocument.4.0")

' transform source document to output document according to
' given XSLT
XmlDoc.transformNodeToObject XmlXSLT, XmlOut

' save output XML document to file
XmlOut.save (XmlOutFile)


Regards,
Theodore.

Quote:
quote:Originally posted by bmains
 Use MSXML2 DOM objects to access each nodes.††I believe you can change the field names.††Don't know the exact objects to do this, but look at both the node and element objects in the SDK.

Brian
Reply With Quote
  #5 (permalink)  
Old April 27th, 2004, 05:02 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Phil,
Between 1 & 3 I went for 3 because in case I change my SQL query to a FOR XML query the xml formatted file I am getting from the "rsTitles.Save szFile, 1 'adPersistXML" does not appear to be in an acceptable xml format.

Regards,
Theodore.

Quote:
quote:Originally posted by pgtips
 Hi Theodore,

I assume this is a continuation of your posts yesterday regarding how to get XML out of SQL Server?

If you want different tag names I see 4 options:
1. use XSLT to transform your current XML into the format you want
2. do as Brian says and use the DOM object to go through the XML one node at a time creating a new DOM object as you go with the tag names you want
3. change your SQL query to a FOR XML query and use field aliases to get the tag names you want
4. use a "standard" SQL query but instead of using the rs.Save method, go through the recordset one row at a time and use a new XML DOM to create XML from the recordset with the tag names you need

Personally I would go with 1 or 3 depending on what XML you have and what XML you need...

hth
Phil
Reply With Quote
Reply


Thread Tools
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
How do I transform XSLT without the <?xml?> tag? nadavvin XSLT 4 June 10th, 2007 10:25 AM
<a> tag in XML sani723 XSLT 5 March 27th, 2007 05:16 AM
<meta> tag is appearing in xml file saurabh_inblore XSLT 2 April 25th, 2006 12:56 AM
XML into <td> crmpicco Classic ASP Basics 4 February 11th, 2005 09:57 AM
HELP HELP ODBC<->ASP <-> XML moon Wrox Book Feedback 1 November 9th, 2003 12:42 PM



All times are GMT -4. The time now is 12:36 PM.


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