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 June 6th, 2008, 08:30 AM
Authorized User
 
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For joefawcett:
I have changed the code become like this:

path = "form/description[desc_id=\""+ test +"\"]/*";

for (i=0;i<nodes.length;i++)
{
  document.write(nodes[i].nodeName);
  document.write(nodes[i].childNodes[0].nodeValue);
}

but there is no result from the looping...
Still like before...
And, where I should put this: setProperty("SelectionLanguage", "XPath")

and, should I use msxml2.domdocment3.0 ?
Because I use Set objDom = server.CreateObject("Microsoft.XMLDOM")
when I add to xml...


For mhkay:

nodes.length means the length of the nodes. The "path" is form/description[desc_id=\""+ test +"\"]//*
So, nodes.length is the length of node description...For example,like the code below, nodes[i], so, "title=Tester" is in the second node...
Start with 0...
I think nodes.length means like that
<form>
  <description>
    ...
  </description>

<description>
    ...
  </description>

<description>
    <title>Tester</title>
  </description>
</form>


 
Old June 6th, 2008, 09:04 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:I have changed the code become like this:

path = "form/description[desc_id=\""+ test +"\"]/*";

for (i=0;i<nodes.length;i++)
{
document.write(nodes[i].nodeName);
document.write(nodes[i].childNodes[0].nodeValue);
}

but there is no result from the looping...
Still like before...
And, where I should put this: setProperty("SelectionLanguage", "XPath")
When you create the Dom
Quote:
quote:
and, should I use msxml2.domdocment3.0 ?
Because I use Set objDom = server.CreateObject("Microsoft.XMLDOM")
when I add to xml...
That's wrong too, you're using a library that's nearly ten years old, things have moved on:
Code:
xmlDom = new ActiveXObject("msxml2.domdocument.3.0");
xmlDom.setProperty("SelectionLanguage", "XPath");
Quote:
quote:
For mhkay:

nodes.length means the length of the nodes.
We know what it means, what is its actual value.

The following code works for me:
Code:
<html>
<head>
    <title>Read XML</title>
    <script type="text/javascript">
    function processXml()
    {
      var xmlDom = new ActiveXObject("MSXML2.DomDocument.3.0");
      xmlDom.setProperty("SelectionLanguage", "XPath");
      xmlDom.async = false;
      xmlDom.load("form.xml");
      var sOldId = "024/HRCS-SP/P/7/98";
      var sXPath = "form/description[desc_id=\""+ sOldId +"\"]/*";
      var colNodes = xmlDom.selectNodes(sXPath);
      var sData = "";
      for (var i = 0, l = colNodes.length; i < l; i++)
      {
        sData += colNodes[i].nodeName + ": " + colNodes[i].childNodes[0].nodeValue + "\n";
      }
      document.getElementById("txtOutput").value = sData;
    }
    </script>
</head>
<body onload="processXml();">
<textarea id="txtOutput" cols="60" rows="30"></textarea>
</body>
</html>
when your xml is stored as form.xml in the same folder.

--

Joe (Microsoft MVP - XML)
 
Old June 6th, 2008, 09:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>nodes.length means the length of the nodes.

nodes.length tells you how many nodes were returned by the path expression. I want to know the value of this, so that we can see whether the path expression is selecting anything.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 6th, 2008, 10:07 AM
Authorized User
 
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It still doesn't work=(
Here is my code in description_update.asp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Update Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body onload="processXml();">
<%
'ASP code to update record to database ...And it has already work well
%>

<script type="text/javascript">
    function processXml()
    {
      var xmlDom = new ActiveXObject("MSXML2.DomDocument.3.0");
      xmlDom.setProperty("SelectionLanguage", "XPath");
      xmlDom.async = false;
      xmlDom.load("description2.xml");
      var sOldId = "<%= oldidname %>";
      var sXPath = "form/description[desc_id=\""+ sOldId +"\"]/*";
      var colNodes = xmlDom.selectNodes(sXPath);
      var sData = "";
      for (var i = 0, l = colNodes.length; i < l; i++)
      {
        sData += colNodes[i].nodeName + ": " + colNodes[i].childNodes[0].nodeValue + "\n";
      }
      document.getElementById("txtOutput").value = sData;
    }

</script>
<textarea id="txtOutput" cols="60" rows="30"></textarea>
</body >
</html>


I try this but only show text area and blank...And when I check in description2.xml, it still does not change..

What's wrong=(



 
Old June 6th, 2008, 10:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well there are three possibilities I can think of:
  • Description2.xml is not in the same folder as the asp file or can't be found for a different reason
  • Description2.xml is not as you've shown it
  • oldidname is not set to what you think it is
If you alert xmlDoc.parseError.errorCode, xmlDoc.parseError.reason and xmlDoc.xml after loading the XML that might help.
It would also help to show the actual view-source of the page as the browser sees it, i.e. after it's been created by the asp engine.

--

Joe (Microsoft MVP - XML)
 
Old June 6th, 2008, 10:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I have asked you for important diagnostic information. If you're not going to supply it, you can't expect any further help.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 6th, 2008, 11:19 AM
Authorized User
 
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For joefawcett:

I have already put xml file in the same folder with the code file.
How and where I can put "alert xmlDoc.parseError.errorCode, xmlDoc.parseError.reason and xmlDoc.xml after loading the XML" ?

description2.xml is pure only like this:
<?xml version="1.0"?>
<form>
    <description>
        <desc_id>024/HRCS-SP/P/7/98</desc_id>
        <title>Kebijakan1</title>
        <dates>25/5/2007</dates>
        <author>Smart</author>
        <file_name>Policy1</file_name>
        <type>doc</type>
        <category>surat_keputusan</category>
        <sub_cat1>tidak_berlaku</sub_cat1>
        <sub_cat2>1981</sub_cat2>
    </description>
...(some data like above)
</form>

And oldidname is variable that I get from ASP variable that is used as id. I mean if I click "update" or "delete" I just want to treat that delete and update to the certain title/author...So, i used oldidname...
And in this case, the contents of oldidname is not just like an integer but also use string for example like this: 024/HRCS-SP/P/7/98


I'm new in java script and XML =( Please help me..

For mhkay:

Actually I do not know the value of nodes.length because when I try like this code below, its show undefined...
This is the code:
var x;
    for (i=0;i<nodes.length;i++)
    {

        x = (nodes.length)
    }
    document.write(x);

And if I want to print something inside looping, it can not show anything. It is just ignored.

 
Old June 6th, 2008, 11:33 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Where do you think you load the XML? The xmlDoc.Load statement of course. As you adamantly refuse to give the information asked for, the actual HTML, there's little more I can suggest.

--

Joe (Microsoft MVP - XML)
 
Old June 6th, 2008, 12:11 PM
Authorized User
 
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I give an alert(xmlDoc.parseError.errorCode);
it shows always 0 in pop up windows.
When I give an alert( xmlDoc.parseError.reason);
it shows Just pop up windows in blank.
When I give an alert( xmlDoc.xml);
it shows all the xml record in pop up windows

 
Old June 7th, 2008, 03:34 AM
Authorized User
 
Join Date: Jun 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallo,
Now, I more understand about my problem. When I tried the code from joefawcett and it does not appear anything, because the data in xml and database was different...I mean, in MS. Access, I have desc_id like this: 024/HRCS-SP/P/7/99 and in xml file, the desc_id still like this: 024/HRCS-SP/P/7/98. So, it is not match between the data in database and xml. After all data in database and xml are same, then that code is working. But it is only show the certain data.
When I click "submit" button, the xml data should be updated.
So, how it can be updated when I click that button?

Here is the code that was sent and I edited a little bit:
<html>
<head>
    <title>Read XML</title>
    <script type="text/javascript">
    function processXml()
    {
      var xmlDom = new ActiveXObject("MSXML2.DomDocument.3.0");
      xmlDom.setProperty("SelectionLanguage", "XPath");
      xmlDom.async = false;
      xmlDom.load("description2.xml");
      var sOldId = "<%= oldidname%>";
      var sXPath = "form/description[desc_id=\""+ sOldId +"\"]/*";
      var colNodes = xmlDom.selectNodes(sXPath);
      var sData = "";
      for (var i = 0, l = colNodes.length; i < l; i++)
      {
        sData += colNodes[i].nodeName + ": " + colNodes[i].childNodes[0].nodeValue + "\n";
      }
      document.getElementById("txtOutput").value = sData;
    }
    </script>
</head>
<body onload="processXml();">
<textarea id="txtOutput" cols="60" rows="30"></textarea>
</body>
</html>
Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit , Translate , Validate XML in one Page moshaik BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 November 24th, 2008 10:37 AM
Edit an XML file semilemon C# 2005 2 April 15th, 2007 02:02 PM
edit gridview anurag_ur ASP.NET 2.0 Basics 3 June 21st, 2006 03:21 AM
How to Edit Attribute Value in XML by ASP.Net sibajibasak XML 1 January 20th, 2005 02:07 AM





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