0

I'm currently delving into the wonderful world of XML.. After having a bit of a tinker with an XML set up there is one thing that has me stumped which I noticed when trying to build a navigation. I'll set up an example below to demonstrate my issue.

<cfxml variable="myXML">
    <navigation>
        <navItem>
            <name>Mens</name>
        </navItem>

        <navItem>
            <name>Womens</name>
        </navItem>
    </navigation>
</cfxml>

<cfset navList = arrayToList(xmlSearch(xmlParse(myXML),
    "string(//navItem/name/text()), "^")>

<cfloop list="#navList#" delimiter="^" index="nav">
    <cfoutput>
        #nav#
    </cfoutput>
</cfloop>

My aim is to have this:

Mens
Womens

This may begin to make sense to some now. I'm trying to return the name value as a string of EACH <navItem> within the XML tree. Of course the error i'm being thrown does make sense, however now i'm stuck as to how I go about returning multiple nodes values as strings.

The error I recieve states:

Unable to process the result of the XMLSearch for A sequence
of more than one item is not allowed as the first argument
of string() (text("Mens"), text("Womens")).

Followed by:

ColdFusion is unable to process the result of the XPath search.
You may have an undefined variable in the xpath expression.

Can anyone point in me along the right lines of what im after?

1 Answer 1

1

I would simply try

<cfset navList = arrayToList(xmlSearch(xmlParse(myXML), "//navItem/name"), "^")>

If that does not work then

<cfset navList = arrayToList(xmlSearch(xmlParse(myXML), "//navItem/name/string()"), "^")>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.