Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
steeban #1
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
-
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... -
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... -
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 ... -
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"... -
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... -
Adam Cameron #2
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
-
steeban #3
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
-
Adam Cameron #4
Re: xmlsearch and xpath
> if i run, i get this :
I thought you said you were getting an empty array?> [the same as me]
Those *are* the values in the XML file. Those array entries are just> 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....
pointers to the relevant nodes in the XML doc. Change one of them, then
dump the original XML... you will see your change.
Yeah it is.> 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......
But it *is* working... you are getting the correct results...?> but first of all
> whether i can get the xmlsearch work fine ????????????
--
Adam
Adam Cameron Guest
-
steeban #5
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
-
steeban #6
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
-
Adam Cameron #7
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
-
steeban #8
Re: xmlsearch and xpath
Hallo Adam,
Thank you
as you said,then this should be the code, which you are suggesting> aSearchResult.xmlAttributes["yourAttribute"] = "new value";
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



Reply With Quote

