Topic "XML Parse - WINSCP"

Author Message
Jappie
[View user's profile]

Joined: 2009-07-24
Posts: 4
Hey All,

Got a question about the XML logging and how to parse these to readable text
This is for example my output: test.xml

<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="test@127.0.0.1" start="2009-07-24T09:30:19.531Z">
<download>
<filename value="/\test\/test_script.txt" />
<destination value="c:\test\test_script.txt" />
<result success="true" />
</download>
</session>


Here is my XML parser i use: xml_parser.html

<html>
<body>
<script type="text/javascript">
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load("test.xml");
document.write("xmlDoc is loaded, ready for use");
}
catch(e) {alert(e.message)}


document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("download");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("filename")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("result")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");

</script>
</body>
</html>



This is not gonna work because the xml_parse.html expects a </filename> and a </result> If i edit the xml file with this it works....

How can i fix this ?


And how can i see after parse only the false results what's in my test.xml ?
So the value result is false and not true.

Thanks in advance,

Jappie

WinSCP version: 2.2.0.105
OS: Win XP Sp3
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
I do not know JavaScript enough to know what's wrong about your code. Though there's nothing wrong about the XML. <filename></filename> and <filename /> are equivalent in XML.

Please see guide to advanced scripting for example for to use XPath to retrieve information from XML.
_________________
Martin Prikryl
Jappie
[View user's profile]

Joined: 2009-07-24
Posts: 4
Thnx for response, i tried the Xpath, but dunno exactly how this works with the XML log. I got it working but it's the same as my first post.
See http://www.w3schools.com/XPath/xpath_examples.asp what i did.

Can you give the right commands for Parsing my example ?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
//w:download/w:filename/@value
//w:download/w:result[@success='false']

I haven't tried them though.
_________________
Martin Prikryl
Jappie
[View user's profile]

Joined: 2009-07-24
Posts: 4
Hmmm, understand what you mean, but can't translate it at the moment to get it work in my example....
Can't find either the log.xml you are using with youre guide to advanced scripting, where can i download it so i can try it on mine and then edit it with youre code you give me.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Jappie wrote:
Can't find either the log.xml you are using with youre guide to advanced scripting, where can i download it so i can try it on mine and then edit it with youre code you give me.

It's not available for download. It is just an example.
_________________
Martin Prikryl
Jappie
[View user's profile]

Joined: 2009-07-24
Posts: 4
ok....then i think i'm stuck.....
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License