Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| 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 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
  #1 (permalink)  
Old April 26th, 2004, 09: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.

  #2 (permalink)  
Old April 26th, 2004, 11:13 AM
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
  #3 (permalink)  
Old April 27th, 2004, 03: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
  #4 (permalink)  
Old April 27th, 2004, 03: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
  #5 (permalink)  
Old April 27th, 2004, 04: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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I transform XSLT without the <?xml?> tag? nadavvin XSLT 4 June 10th, 2007 09:25 AM
<a> tag in XML sani723 XSLT 5 March 27th, 2007 04:16 AM
<meta> tag is appearing in xml file saurabh_inblore XSLT 2 April 24th, 2006 11:56 PM
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





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