 |
| 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
|
|
|
|

October 28th, 2003, 04:41 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Create processing instruction in XSL
Hi all, I am trying to create a XML file ... however, I wanted to add another processing instruction in the XML file so that the xml file can display the way I wanted. But I can't seem to be able to add the XSL processing instruction into my XML file. My code to create XML file is follow:-
===============================
.....
'Create the xml processing instruction.
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
'This is waht I wish to appear in the xml file.
-------> Set objPI2 = objDom.createProcessingInstruction("xml-stylesheet", "type='text/xsl'", "href='simple.xsl'")
'Append the processing instruction to th ' e XML document.
objDom.insertBefore objPI, objDom.childNodes(0)
'Append the XSL PI after the XML PI
-----> objDom.insertAfter objPI2, objPI
================================================== =
Is that doable? Or it's impossible to create an XML with 2 PIs???
|
|

October 29th, 2003, 05:14 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
The first one isn't a processing instruction, it's the xml declaration or prolog although you can create it using the method you are employing.
Yes, you can create the second one but you just pass it one long string:
Code:
Set objPI2 = objDom.createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='simple.xsl'")
Joe (MVP - xml)
|
|

October 29th, 2003, 01:57 PM
|
|
Authorized User
|
|
Join Date: Oct 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe, the XML file came out put the second declaration first ... how can I put it to display the first prolog, then second?? And I realized it doesn't has insertAfter methods :(
================================================== =============
'Create the xml processing instruction.
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
Set objPI2 = objDom.createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='simple.xsl'")
'Append the processing instruction to the XML document.
objDom.insertBefore objPI, objDom.childNodes(0)
objDom.insertBefore objPI2, objDom.childNodes(0)
|
|

October 30th, 2003, 05:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Code:
'Create the xml processing instruction.
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
Set objPI2 = objDom.createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='simple.xsl'")
'Append the processing instruction to the XML document.
objDom.insertBefore objPI, objDom.childNodes(0)
objDom.appendChild objPI2
appendChild adds the node to the end of the current child nodes.
Joe (MVP - xml)
|
|

November 4th, 2003, 12:51 PM
|
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe, sorry for the late reply. I was moving to a new place last week. The 'appendChild' properties add the second declaration(xsl) AFTER all the nodes ... :(
Code:
=================================
Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
Set objPI2 = objDom.createProcessingInstruction("xml-stylesheet", "type='text/xsl' href='simple.xsl'")
'Append the processing instruction to the XML document.
objDom.insertBefore objPI, objDom.childNodes(0)
objDom.appendChild objPI2
=================================
Output:
=================================
<?xml version="1.0"?>
<Name>Mike</Name>
<?xml-stylesheet type='text/xsl' href='simple.xsl'?>
=================================
|
|

November 7th, 2003, 11:15 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Well call it earlier...
--
Joe
|
|

May 7th, 2004, 12:14 PM
|
|
Registered User
|
|
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey guys this is the way to do it
It has been broken up to make it self explanatory..otherwise
a few lines are dovetailed in my implementation
*****************************************
Dim transform As XslTransform = New XslTransform()
transform.Load("ABCD.xsl")
pRateResponseXML = New XmlDocument()
pRateResponseXML.load("EFG.xml")
Dim xReader As XmlReader = transform.Transform(responseXML, Nothing)
pRateResponseXML.Load(xReader)
transform = Nothing
SetRatePackageResponse = True
|
|
 |