Coldfusion finding a word in xml file.

Discussion in 'Programming' started by Hellcrasher, Oct 26, 2006.

  1. #1
    I Cant resolve an issue finding word in a xml file with coldfusion.
    If the xml file looks like this:


    
    <Ark>
        <Fields Apple_id="Apple2" Red_id="Red2">
    <Ark>
    
    Code (markup):

    So how can i make it to find the Apple_id and Red_id From the tag <Fields> ?
    To use those later in like Insert command.
     
    Hellcrasher, Oct 26, 2006 IP
  2. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    <cffile action="read" file="#NameOfFile#" variable="XMLFile">
    <cfif IsXML(XMLFile)>
    Processing...
    <cfflush>
    <cfset XMLDoc = XMLParse(XMLFile)>
    <cfset Items = XMLSearch(XMLDoc,"/Ark")>
    <cfloop from="1" to="#ArrayLen(Items)#" index="I">
    <cfoutput>
    <br>#Items.Fields.XMLAttributes.Apple_ID#
    <br>#Items.Fields.XMLAttributes.Red_ID#
    </cfoutput>
    </cfloop>
    <cfelse>
    Sorry not an XML File
    </cfif>
     
    datropics, Oct 26, 2006 IP
  3. Hellcrasher

    Hellcrasher Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    With it gives the value of apple_id and Red_id.
    But i need to get it to work so that the apple_id and Red_id could be anything like (app3le_id and just red) and it would find those without me giving the name for it.
    I have told to use findnocase and left commands for that case but i havent figured yet how.
    But still thanks for response.
     
    Hellcrasher, Oct 26, 2006 IP
  4. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #4
    What do do is, place .XMLAttributes into a structure and loop through it
     
    datropics, Oct 26, 2006 IP
  5. Hellcrasher

    Hellcrasher Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it doesnt help , because i dont need the value.. i just need to put it finding the words apple_id , Red_id... As that i can change to anything like Redlabel_id and it can find the correct name. Without me writing that specific name in any command.
     
    Hellcrasher, Oct 26, 2006 IP
  6. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #6
    no worries - when you loop through XMLAttributes, you will be looping through a COLLECTION. and the KEY would be the attribute - so, once you get the Key you can change it's name (or rather assign the new name to another variable while rebuilding the XML) and continue

    what do you think?
     
    datropics, Oct 26, 2006 IP
  7. Hellcrasher

    Hellcrasher Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I didnt correctly understand your last post. What i need to do at all is to make it work so that random Xml files can be added straight to database through web when they contain same base structure.

    Added you to my msn too if its ok.
     
    Hellcrasher, Oct 26, 2006 IP
  8. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #8
    oh wow!!! that sounds exciting

    Ok - no worries - I'll think about the code tonight and get back to you - next question, how is the database setup?
     
    datropics, Oct 26, 2006 IP
  9. Hellcrasher

    Hellcrasher Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hmm.... damn i dont know exactly how to explain it.
    I am just doing CF coding for my boss. In my comp Oracle is running on windows but in the original site it is on Linux i think.
    If anything else you need to ask then contact me in msn if its ok.
     
    Hellcrasher, Oct 26, 2006 IP
  10. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #10
    lol - no I mean the table structure

    record id, field, etc
     
    datropics, Oct 26, 2006 IP
  11. Hellcrasher

    Hellcrasher Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Ok trying to explain again as i can to all the people.
    I could use some help to use the Find and Left or mid command..
    To find the word what contains the element before the = symbol.
    (Xml file example in first post )

    Or any other solution but with same perspectives...

    Thanks..
     
    Hellcrasher, Oct 26, 2006 IP
  12. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #12
    HellCrasher,

    How did the file I sent you work out?
     
    datropics, Oct 27, 2006 IP
  13. Hellcrasher

    Hellcrasher Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thanks alot for your help. It worked out really fine.
     
    Hellcrasher, Oct 27, 2006 IP