Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:35:51+00:00 2026-05-26T19:35:51+00:00

I need to get key/value pairs from XML to populate member info on a

  • 0

I need to get key/value pairs from XML to populate member info on a website. Here’s a sample of the XML:

<a:PObject xmlns:b="http://schemas.datacontract.org">
<b:CanUpsert>true</b:CanUpsert>
<b:Fields xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <c:KeyValueOfstringanyType>
        <c:Key>FirstName</c:Key>
        <c:Value i:type="d:long" xmlns:d="http://www.w3.org/2001/XMLSchema">Joe</c:Value>
    </c:KeyValueOfstringanyType>
    <c:KeyValueOfstringanyType>
        <c:Key>LastName</c:Key>
        <c:Value i:type="d:long" xmlns:d="http://www.w3.org/2001/XMLSchema">Mama</c:Value>
    </c:KeyValueOfstringanyType>
</b:Fields>
</a:PObject>

I am new to XML and am having a tough time with the prefixes. I am using the following to give me an array of Key/Value pairs:

<cfset keyValue = xmlSearch(soapBody,"//*[local-name()='Key'] | //*[local-name()='Value']") />

I am able to reference the data I need by index; this works well for the most part, but for some reason not every record has its data in the same place. That is, #keyValue[4]# works in 95% of the records, but in a few, gives me a totally different value!

I have read many posts on this subject here and elsewhere; none of them get me around the prefix issue. For example, I can access an element by name using

<cfset firstNameKey = XmlSearch(soapBody,"//*[ text() = 'FirstName' ]") />

but how would I get the corresponding value? I’ve tried using following-sibling, but must not have done it correctly… I even tried stripping out all of the prefixes — nothing worked after that!

Thank you all so much in advance for any advice or suggestions you can give me. As I said, I am new to XML (and not that advanced in CF either) and am looking forward to getting pointed in the right direction. Thanks alot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:35:52+00:00Added an answer on May 26, 2026 at 7:35 pm

    I would suggest a simpler means than xpath – convert the XML string to an object with xmlparse() and then iterate over the elements you need, using cf code to construct the name-value pairs. Cfdump the XML object to see what the resulting structure looks like – should be pretty straightforward. Give it a shot.

    edit

    After working on this a bit, I have some working code for you:

    <cfsavecontent variable="xmldata">
    <PObject xmlns:b="http://schemas.datacontract.org">
    <b:CanUpsert>true</b:CanUpsert>
    <b:Fields xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        <c:KeyValueOfstringanyType>
            <c:Key>FirstName</c:Key>
            <c:Value type="d:long" xmlns:d="http://www.w3.org/2001/XMLSchema">Joe</c:Value>
        </c:KeyValueOfstringanyType>
        <c:KeyValueOfstringanyType>
            <c:Key>LastName</c:Key>
            <c:Value type="d:long" xmlns:d="http://www.w3.org/2001/XMLSchema">Mama</c:Value>
        </c:KeyValueOfstringanyType>
    </b:Fields>
    </PObject>
    </cfsavecontent>
    
    <cfset xmlObj = xmlParse(xmldata)>
    <cfset valueArray = xmlSearch(xmlObj,"//*[local-name()='KeyValueOfstringanyType']")>
    <cfset nameValuePairs = {}>
    <cfloop from="1" to="#ArrayLen(valueArray)#" index="i">
            <cfset name = xmlSearch(valueArray[i], "c:Key")[1].xmlText>
            <cfset value = xmlSearch(valueArray[i], "c:Value")[1].xmlText>
            <cfset nameValuePairs[name] = value>
    </cfloop>
    <cfdump var="#nameValuePairs#">
    

    Note, I had to modify your xml sample slightly, since there were some references to namespaces that were not defined. Anyhow – the above works for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand one thing. If I want to get JSON data (key-value-pairs) from
I need a regex for parsing key-value-pairs from a properties-file to write them into
A bunch of key/value pairs, from an object that may have duplicate keys, need
I'm making a xml image gallery. And I need get the path from parent,
Ive had this solution to my JComboBox to get the effect of Key/Value pairs
I have the first key/value pair in a LinkedHashMap, which I get from a
I need to get just the first item (actually, just the first key) off
I have two tables with a weak relation. I need get a text value
@noresultHere favData.searchDict is a dictionary object, it consists of 3 key/value pairs, actually the
Problem I need a key-value store that can store values of the following form:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.