login about faq

Hello,

I'm attempting to use Chilkat_9_5_0.Xml. Here is a test xml document that I'm using to test Chilkat XML methods, and it's giving me unexpected results. (This is a shortened version of an XML file returned by Chilkat Ftp2)

Basically, I'm looking for file name, file size, and path information. The xml file has some <file> nodes at the root, and some under two levels of <dir> nodes, and I'm having trouble figuring out how to navigate the xml file so that I can download files I'm missing into the same directory structure. (I don't want all of them, just files that don't exist or that are the wrong size, so I can't just download the whole thing.)

<?xml version="1.0" encoding="utf-8" ?>
<dirTree>
    <file sz="34731" dt="Sun, 27 Jul 2014 05:00:00 -0400">140725AM.lmt</file>
    <file sz="24719" dt="Mon, 28 Jul 2014 05:00:00 -0400">140725CN.lmt</file>
    </file>
    <dir name="20140727">
        <dir name="Update_1">
            <file sz="34731" dt="Sun, 27 Jul 2014 05:00:00 -0400">140725AM.lmt</file>
            <file sz="237576" dt="Sun, 27 Jul 2014 05:00:00 -0400">140727LS.lmt</file>
            <file sz="225952" dt="Sun, 27 Jul 2014 05:00:00 -0400">140727PD.lmt</file>
        </dir>
    </dir>
    <dir name="20140729">
        <dir name="Update_1">
            <file sz="44585" dt="Tue, 29 Jul 2014 05:00:00 -0400">140728AM.lmt</file>
            <file sz="24405" dt="Tue, 29 Jul 2014 05:00:00 -0400">140728CN.lmt</file>
            <file sz="134287" dt="Tue, 29 Jul 2014 05:00:00 -0400">140728WH.lm</file>
        </dir>
    </dir>
    <dir name="20140728">
        <dir name="Update_1">
            <file sz="24719" dt="Mon, 28 Jul 2014 05:00:00 -0400">140725CN.lmt</file>
            <file sz="25025" dt="Mon, 28 Jul 2014 05:00:00 -0400">140726CN.lmt</file>
            <file sz="25115" dt="Mon, 28 Jul 2014 05:00:00 -0400">140727CN.lmt</file>
            <file sz="152048" dt="Mon, 28 Jul 2014 05:00:00 -0400">140728AN.lmt</file>
            <file sz="138385" dt="Mon, 28 Jul 2014 05:00:00 -0400">140728ET.lmt</file>
            <file sz="163350" dt="Mon, 28 Jul 2014 05:00:00 -0400">140728GC.lmt</file>
        </dir>
        <dir name="Update_2">
            <file sz="83054" dt="Wed, 30 Jul 2014 05:15:00 -0400">140730HH.lmt</file>
        </dir>
    </dir>
</dirTree>

Here is some test code that gives peculiar results:

   strXml = WScript.Arguments.Item(0)
    set FileTreeXml = CreateObject("Chilkat_9_5_0.Xml")
    success = FileTreeXml.LoadXmlFile(strXml)
'If there is a directory, it's at the root, and I should be able to get 
'its name here, no navigating.
sDir = FileTreeXml.GetAttrValue("name")
wscript.echo "* sDir=" & sDir

'stepping through children 'The first child is a directory, and I can get its name by navigating to the first child

success = FileTreeXml.FirstChild2()
sSubDir = FileTreeXml.GetAttrValue("name")
wscript.echo "** sSubDir=" & sSubDir

'note also that the files are the children of the last directory to have a name, so there is no need to navigate further

sName = FileTreeXml.GetChildContent("file")
wscript.echo "*** sName=" & sName

'useful strategy for getting all the files at this node...
sName = FileTreeXml.GetChildContentByIndex(0)      'etc...
wscript.echo "**** sName=" & sName

Here are the results:

    • sDir=20140728
  1. ** sSubDir=Update_1
  2. *** sName=140725CN.lmt
  3. **** sName=140725CN.lmt

And here is my problem: The first <dir> node doesn't have the name 20140728 (That's the name of the third "dir" node.) And the other results all apply to that 3rd <dir> node. I like the conistancy, but I don't know why my pointer has ended up there.

Can anyone explain why this is happening? And if anyone has ideas about the best way to get the "file" node and path info when my xml file has those nodes at two different levels, I'd be grateful to hear them.

Thank you to all. Judith

asked Aug 04 '14 at 17:22

Judith's gravatar image

Judith
11135


The XML appears to be malformed - there is an extra </file> closing tag near the top of the <dirTree> content.

After fixing that, you should be able to traverse the tree properly.

link

answered Aug 04 '14 at 18:16

jpbro's gravatar image

jpbro ♦
1.1k2618

Oh, so simple!! And I didn't see it.

Thank you again jpbro.

Judith

(Aug 04 '14 at 20:04) Judith

Glad to help.

(Aug 04 '14 at 21:14) jpbro ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×59
×5
×1

Asked: Aug 04 '14 at 17:22

Seen: 986 times

Last updated: Aug 04 '14 at 21:14

powered by OSQA