Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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 9th, 2003, 06:21 PM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to create a string from XML Island in HTML?

Hi there,

I want to display some address data in HTML page using XSL. I can use xml file to display in the HTML page. But, I want to do the same thing using XML Island embedded in to HTML ("XMLID" xml portion in the below HTML code)

I want to use loadXML() (as in the below ProcessXML1()), how ca I convert this "XMLID" xml island to a string?

function ProcessXML1() {

    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
       xmlDoc.loadXML("<customer><first_name>Joe</first_name><last_name>Smith</last_name></customer>");
    if (xmlDoc.parseError.errorCode <> 0) {
       var myErr = xmlDoc.parseError
       alert("You have error " + myErr.reason);
     }
}


Thanks in advance,
Chandima


<html>
<head>
<body>

<xml id="XMLID">
<?xml version="1.0" ?>
 <Address>
  <name> ABC
    <phone>1234</phone>
    <cell>111111</cell>
  </name>
  <name>EFG
    <phone>77777777</phone>
    <cell>99999999 </cell>
  </name>
 </Address>
</xml>

<script language="JavaScript">
    function ProcessXML() {
    // Load XML
    var xml = new ActiveXObject("Microsoft.XMLDOM")
    xml.async = false
    //xml.load("addresses.xml") -- This works fine, but I want to use above XML Island instead of this addresses.xml file

    // Load XSL
    var xsl = new ActiveXObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load("addresses.xsl")

    // Transform
    document.write(xml.transformNode(xsl))
    }

</script>
<input type="button" onClick=ProcessXML()>
</body>
</html>


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

If you're sure that version 4 is installed then use your first function with the following change:
Code:
function ProcessXML1() {

    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
    xmlDoc.async = false;
    xmlDoc.resolveExternals = false;
       xmlDoc.load(XMLID.XMLDocument);
/* OR
xmlDoc.loadXML(XMLID.XMLDocument.xml);
*/
    if (xmlDoc.parseError.errorCode != 0) {
       var myErr = xmlDoc.parseError
       alert("You have error " + myErr.reason);
     }
otherwise use the following prog id "Msxml2.DOMDocument.3.0".
and use:
Code:
xmlDoc.setProperty("SelectionLanguage", "XPath");
as your next line
Never use "Microsoft.XmlDom" unless you need to support version 1 and 2 machines.
The inequality operator in JavaScript is !=.

--

Joe
 
Old October 10th, 2003, 02:08 PM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. Joe. It works...


Chandima







Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Data Island Display Problem marcuslim XML 8 December 7th, 2004 04:00 AM
Converting an XML data island to 2 arrays NeilAtWork Classic ASP XML 0 April 14th, 2004 10:38 AM





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