Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default xmlsearch and xpath

    Hallo all,
    i have a small problem in xmlsearch and i am new to coldfusion....

    The below is the xupdate packet from flash send to coldfusion
    <?xml version="1.0"?>
    <xupdate:modifications version="1.0"
    xmlns:xupdate="http://www.xmldb.org/xupdate">
    <xupdate:update select="/si/menu[@type='Edit' ]/@type">Exit</xupdate:update>
    <xupdate:update select="/si/menu[@type='Select' ]/@type">Sel</xupdate:update>
    </xupdate:modifications>

    i want all the xupdate:update nodes.......
    and this is the coldfusion code
    <cfset sel = XmlSearch(xupd, "/xupdate:modifications/xupdate:update")>

    but i am getting empty array...
    I saw many forums indicating the xmlns attribute, to delete this attribute....
    After deleting also, it is not working,
    the xml file is parsing but the xmlsearch is not working

    what's the problem in this code or in xml ???
    or because of the xml namespaces ---- xupdate:modifications ??
    Is there any way to do this ???

    can anyone help me please.....!!!!

    steeban Guest

  2. Similar Questions and Discussions

    1. XMLParse and XMLSearch
      I have the following code: a variable "x" that contains an XML string; if I do an XMLParse on this variable, it works (cfdump shows me the xml...
    2. xml and xmlsearch
      Hi all, I am new to coldfusion, and i am facing lots of problem.... can anyone solve my problem I am reading an xml file through cfm and using...
    3. how to access the array returned from xmlsearch
      I am having an xmlsearch function, from which i am getting the attributes of the nodes, which satisfy Only one element is returned that is ...
    4. XMLSearch. doesnt work
      hi i'm trying to use xmlsearch function but for some strange reasons it returns only an empty array here the xml file <?xml version="1.0"...
    5. Could I use XPATH?
      Im currently using the XML doc below. At the moment I am pulling the first 'site index' value out, and using that value for a CFHTTP request. I...
  3. #2

    Default Re: xmlsearch and xpath

    G'day

    I tried this test rig:
    <cfset s="<?xml version=""1.0""?>
    <xupdate:modifications version=""1.0""
    xmlns:xupdate=""http://www.xmldb.org/xupdate"">
    <xupdate:update select=""/si/menu[@type='Edit'
    ]/@type"">Exit</xupdate:update>
    <xupdate:update select=""/si/menu[@type='Select'
    ]/@type"">Sel</xupdate:update>
    </xupdate:modifications>
    ">

    <cfset x = xmlParse(s)>
    <cfset a=xmlSearch(x, "/xupdate:modifications/xupdate:update")>
    <cfdump var="#a#">

    And got these results:

    array
    1
    xml element
    XmlName xupdate:update
    XmlNsPrefix xupdate
    XmlNsURI [url]http://www.xmldb.org/xupdate[/url]
    XmlText Exit
    XmlComment
    XmlAttributes
    struct
    select /si/menu[@type='Edit' ]/@type
    XmlChildren
    2
    xml element
    XmlName xupdate:update
    XmlNsPrefix xupdate
    XmlNsURI [url]http://www.xmldb.org/xupdate[/url]
    XmlText Sel
    XmlComment
    XmlAttributes
    struct
    select /si/menu[@type='Select' ]/@type
    XmlChildren

    Which sounds about right to me. This is on CFMX7.

    What do you get if you run that test rig?

    --

    Adam
    Adam Cameron Guest

  4. #3

    Default Re: xmlsearch and xpath

    Thanks for your reply
    I am using cf 6.1 (developer edition)

    if i run, i get this :
    --------------------------------------------------------------------
    array
    1 xml element
    XmlName xupdate:update
    XmlNsPrefix xupdate
    XmlNsURI [url]http://www.xmldb.org/xupdate[/url]
    XmlText Exit
    XmlComment
    XmlAttributes struct
    select /si/menu[@type='Edit' ]/@type

    XmlChildren

    2 xml element
    XmlName xupdate:update
    XmlNsPrefix xupdate
    XmlNsURI [url]http://www.xmldb.org/xupdate[/url]
    XmlText Sel
    XmlComment
    XmlAttributes struct
    select /si/menu[@type='Select' ]/@type

    XmlChildren
    -----------------------------------------------------------------
    and one more thing, if i use the xmlsearch it returns an array,
    and I am not able to reach that value in the actual xml file....
    With the returned array, i think there is no use,
    but in flash, actually it will filter the xml file and returns the xml file
    itself, so if i make any corrections, it reflects... but in coldfusion, this is
    not the case......
    so is there any way ??

    but first of all
    whether i can get the xmlsearch work fine ????????????




    steeban Guest

  5. #4

    Default Re: xmlsearch and xpath

    > if i run, i get this :
    > [the same as me]
    I thought you said you were getting an empty array?
    > and one more thing, if i use the xmlsearch it returns an array,
    > and I am not able to reach that value in the actual xml file....
    Those *are* the values in the XML file. Those array entries are just
    pointers to the relevant nodes in the XML doc. Change one of them, then
    dump the original XML... you will see your change.
    > but in flash, actually it will filter the xml file and returns the xml file
    > itself, so if i make any corrections, it reflects... but in coldfusion, this is
    > not the case......
    Yeah it is.
    > but first of all
    > whether i can get the xmlsearch work fine ????????????
    But it *is* working... you are getting the correct results...?

    --

    Adam
    Adam Cameron Guest

  6. #5

    Default Re: xmlsearch and xpath

    thank you,
    i some how managed to get my xmlsearch to work....
    thank you again!!!
    now I am having an xmlsearch function, from which i am getting the attributes
    of the nodes, which satisfy....
    Only one element is returned that is

    selected[1] = <?xml version="1.0" encoding="UTF-8"?>macromedia

    As you said, if i assign
    selected[1] = "Coldfusion"
    and dump the xmlobject, it is not changing....it is with the old values

    Now what's the problem is, i want to get from the selected array - the value
    "macromedia" alone,
    but i had tried, it is returning wiht the xmlcomment...
    selected[1].xmltext --- returns nothing
    selected[1].xmlattributes --- returns nothing


    Is there any way ??
    please help

    steeban Guest

  7. #6

    Default Re: xmlsearch and xpath

    Hi,
    this is the xml file
    - <spi>
    <menu type="Macromedia" u="macromedia.com" />
    <menu type="Supports" u="support.com" />
    ---------------
    ---------------
    </spi>

    And below is the cfm file code
    <cffile action="read" file="C:\Inetpub\wwwroot\cold\main.xml"
    variable="myxml">
    <cfscript>
    myxmldoc = XmlParse(myxml);
    selectedElements = XmlSearch(myxmldoc, "/spi/menu/@type");
    for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1){
    writeoutput(selectedElements.XmlText & "<br>" &
    selectedElements.XmlAttributes & "<br>");
    }
    </cfscript>
    <cfdump var="#myxmldoc#">
    <cfdump var="#selectedElements#">

    And I get only errors, Can you solve this problem!!!!
    please!!!!!!!

    steeban Guest

  8. #7

    Default Re: xmlsearch and xpath

    > selected[1] = <?xml version="1.0" encoding="UTF-8"?>macromedia

    Oh, OK. Rather than pull back just the attribute values, pull back the
    whole node. Then you can change the attribute values via:

    aSearchResult[i].xmlAttributes["yourAttribute"] = "new value";

    (where aSearchResult is what you get back form the xmlSearch() call).

    --

    Adam
    Adam Cameron Guest

  9. #8

    Default Re: xmlsearch and xpath

    Hallo Adam,
    Thank you
    as you said,
    > aSearchResult.xmlAttributes["yourAttribute"] = "new value";
    then this should be the code, which you are suggesting
    selected[1].xmlAttributes["type"]

    the above code, I tried before asking in this forum,
    and it returns error, and the error displayed is
    "You have attempted to dereference a scalar variable of type class
    coldfusion.runtime.Array as a structure with members."
    how to solve this problem or how to edit the type attribute using
    xmlsearch................please

    I had also specified the xml file and the xmlsearch i use,
    can you suggest any other way to do this....

    this is the xml file
    - <home>
    <menu type="Macromedia" u="macromedia.com" />
    <menu type="Supports" u="support.com" />
    ---------------
    ---------------
    </home>

    And below is the cfm file code
    <cffile action="read" file="C:\Inetpub\wwwroot\cold\main.xml" variable="myxml">
    <cfscript>
    myxmldoc = XmlParse(myxml);
    selectedElements = XmlSearch(myxmldoc, "/home/menu/@type");
    for (i = 1; i LTE ArrayLen(selectedElements); i = i + 1){
    writeoutput(selectedElements.XmlText & "<br>" & selectedElements.XmlAttributes
    & "<br>");
    }
    </cfscript>
    <cfdump var="#myxmldoc#">
    <cfdump var="#selectedElements#">

    please,
    how to do this ??????
    can u check the code and tell me.....???
    please help

    steeban Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139