Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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
 
Old October 28th, 2003, 04:41 PM
Authorized User
 
Join Date: Oct 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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???

 
Old October 29th, 2003, 05:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old October 29th, 2003, 01:57 PM
Authorized User
 
Join Date: Oct 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)



 
Old October 30th, 2003, 05:26 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old November 4th, 2003, 12:51 PM
Authorized User
 
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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'?>
=================================


 
Old November 7th, 2003, 11:15 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well call it earlier...

--

Joe
 
Old May 7th, 2004, 12:14 PM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional processing in XSL francislang XSLT 2 March 18th, 2008 12:04 AM
Create generic XSL Template to create table Venkatachalapathy XSLT 5 March 11th, 2008 07:49 AM
xsl:result-document instruction bonekrusher XSLT 3 April 12th, 2007 06:01 PM
processing instruction vs. element bcogney XML 6 April 10th, 2007 03:46 PM
XSL processing question.. eladner XSLT 1 August 24th, 2004 07:58 AM





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