Skip to main content
BreakawayPaul
Inspiring
September 19, 2012
Question

Need help reading an XML file

  • September 19, 2012
  • 1 reply
  • 606 views

I'm trying to read an XML document for an item, and it's having inconsistent results.

Example:

XML doc:

  <acronym>

    <name>binghamton_ny</name>

    <old>Binghamton Ny</old>

    <new>Binghamton, NY</new>

  </acronym>

  <acronym>

    <name>burlington_vt</name>

    <old>Burlington Vt</old>

    <new>Burlington, VT</new>

  </acronym>

  <acronym>

    <name>champaign_il</name>

    <old>Champaign Il</old>

    <new>Champaign, IL</new>

  </acronym>

Code:

<cfloop list="#dirList#" index="d" delimiters="|">

    <cfloop query="chngCurrent">

        <cfif REFind("\b#old#\b",d) NEQ 0>

            <cfset newD = REreplace(d,"\b#old#\b",new,"ALL") />

        </cfif>

     </cfloop>

</cfloop>

The REFind doesn't always find the match, even though there is one.  I have no idea why it's being so annoying.

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 19, 2012

    The REFind doesn't always find the match, even though there is one.  I have no idea why it's being so annoying.

    Err... no.  If there was a match, reFind() would be finding it.  What you mean is that what you are telling reFind() to look for might not be what you ought to be telling it to look for.

    Your code doesn't tell us where #old# is coming from.  I presume it's a column in the query?  What is its exact value when the reFind() is not finding it?

    And to be frank, I can't tell what you're trying to do here?  What's dirList?  I am gusssing it's got something to do with that XML you posted?

    Can you ask your question from the perspective that the audience reading it has absolutely nothing to go on other than what you write down?  We can't infer stuff that might be obvious to you...

    Cheers.

    --

    Adam

    BreakawayPaul
    Inspiring
    September 20, 2012

    Hrm, some of what I thought I pasted didn't show up.

    Alright, what's going on here is that I have a dynamic breadcrumb script that I wrote.  It basically uses the current URL to build a breadcrumb list.

    Example:

    www.ourdomain.com/planning/land_use/tool_kit/

    would generate:

    Home > Planning > Land Use > Tool Kit

    It basically explodes the path and uses a rereplace to make the link text look good.  The problem is that it doesn't always work (invalid characters in URL, etc).

    So we've written a routine to run the folder names against an XML file (we did this because we STILL have to use MS Access for a database, and we wanted to reduce the number of queries).  It works most of the time, but sometimes for no apparent reason, it doesn't seem to come up with a match.

    'dirlist' is a pipe delimited list of the directories from the current URL.

    'old' is the current folder name from the loop

    'new' is what it's supposed to return when it finds a match

    I can cfoutput 'old' and I can see the folder name, and if I cfdump the query of the XML file, I can see it in there, but it's not returning a match.  Maybe I should just stick it in a db table and not worry about another hit on the db.

    BreakawayPaul
    Inspiring
    September 21, 2012

    Solved.

    I changed Refind() to RefindNoCase() and ReReplace to ReReplaceNoCase().

    I totally overlooked the fact that there was a regex applying title case to the text before it ever made it to the script.  I guess this is one of the drawbacks to having a coder on your team who does a lot of work, then leaves for greener pastures.

    Thanks for the second pair of eyes.