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

  • Home
  • SEARCH
  • 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 8939061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:45:17+00:00 2026-06-15T10:45:17+00:00

I’m working on a project which will post periodic XML updates for users. I’m

  • 0

I’m working on a project which will post periodic XML updates for users. I’m attempting to suppress information which hasn’t changed since the last update.

Within node.js, I have assembled a user object which will be used to generate the XML:

users = 
  # actual application has 25 properties per user
  [
    {
      USERID: 150927,
      EMAIL: 'irving.block@email.net',
      FIRSTNAME: 'Irving',
      LASTNAME: 'Block',
      COLOR: 'Green'
    },
    {
      USERID: 1246007,
      EMAIL: 'allen.adler@email.net',
      FIRSTNAME: 'Adler',
      LASTNAME: 'Allen',
      COLOR: 'Blue'
    },
    {
      CLKEY: 1248350,
      EMAIL: 'walter.pidgeon@email.net',
      FIRSTNAME: 'Walter',
      LASTNAME: 'Pidgeon',
      COLOR: 'Red'
    }
  ]

I also have an object loaded which helps map user data to the eventual XML fields:

xml_map =
  [
    {
      ID: 1,
      ELEMENT: 'xml_map_assigned_id',
      MAPPPED: 'USERID' 
    },
    {
      ID: 2,
      ELEMENT: 'xml_map_email_address',
      MAPPPED: 'EMAIL' 
    },
    {
      ID: 3,
      ELEMENT: 'xml_map_user_firstname',
      MAPPPED: 'FIRSTNAME' 
    },
    {
      ID: 4,
      ELEMENT: 'xml_map_user_lastname',
      MAPPPED: 'LASTNAME' 
    },
    {
      ID: 5,
      ELEMENT: 'xml_map_user_color',
      MAPPED: 'COLOR'
    }
  ]

Using these objects, I need to compare with the last update, and remove matching properties (since I only want to post updates for data that has changed). Here’s an example of what the last update (stored in the DB) might look like:

# nothing like this is used in the real application
# just showing here to give an idea of what the DB could look like
db_data = 
  [ 
    {
      USERID: 150927,
      EMAIL: 'irving.block@email.net',
      FIRSTNAME: 'IRVING',
      LASTNAME: 'Block',
      COLOR: 'Orange'
    },
    {
      USERID: 1246007,
      EMAIL: 'new.email@somewhere.com',
      FIRSTNAME: 'Adler',
      LASTNAME: 'Allen',
      COLOR: 'Blue'
    },
    {
      USERID: 1248350,
      EMAIL: 'walter.pidgeon@email.net',
      FIRSTNAME: 'Walt',
      LASTNAME: 'Pidgeon',
      COLOR: 'Red'
    }
  ]

Using these examples, I’d like to end up with a User object like this (since only 1 thing has changed for each user):

users_final = 
  [
    {
      USERID: 150927,
      COLOR: 'Orange'
    },
    {
      USERID: 1246007,
      EMAIL: 'new.email@somewhere.com',
    },
    {
      USERID: 1248350,
      FIRSTNAME: 'Walt',
    }
  ]

And now for the pseudo-code that shows how I’ve been trying to accomplish this:

async = require "async"

handleChanges = (users, map, callback) ->
  sql1 = "select..."
  sql2 = "update..."
  sql3 = "insert..."
  db.query sql1, [], (err, rows, def) ->
    if err? then console.log err
    if rows[0]
      if rows[0].ELEMENT_VALUE.toString() is users[map.MAPPED].toString() 
      # nothing has changed since last update
        db.query sql2, ['Old'], (err, rows, def) ->
          if err? then console.log err
          callback null, map.MAPPED
      else # this value has changed since the last update. Run update query
        db.query sql2, ['New'], (err, rows, def) ->
          if err? then console.log err
          callback null, null
    else # no value has ever been saved for this combo. Run insert query
      db.query sql3, [], (err, rows, def) ->
        if err? then console.log err
        callback null, null

updateStore = (users, callback) ->
  for map in xml_map
    do(map) ->
      handleChanges users, map, (err, del) ->
        if del? then delete r[del]
  callback null, r

async.map users, updateStore, (err, results) ->
  console.log results

This obviously doesn’t work right. I’m sure the updateStore function needs to be doing something different, but I’m at a loss.

Thanks in advance for your help!

  • 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-06-15T10:45:18+00:00Added an answer on June 15, 2026 at 10:45 am

    I did similar thing in the project, but I use json instead of xml.

    What I have done is
    retrieve a list of objects from db. and calculate a hash value for each of the object.

    users = 
      [
        {
          USERID: 150927,
          EMAIL: 'irving.block@email.net',
          FIRSTNAME: 'Irving',
          LASTNAME: 'Block',
          COLOR: 'Green'
        },
        {
          USERID: 1246007,
          EMAIL: 'allen.adler@email.net',
          FIRSTNAME: 'Adler',
          LASTNAME: 'Allen',
          COLOR: 'Blue'
        }
      ]
    hash = [
      'c8addc875913a367486ba8343f68e349667e0334',
      'df3d067e876437996237d0fde90466703ea303b9'
    ]
    

    on the client side, I do compare the each old hash to the new hash. if different I use php.js or underscore.js. php.js can do array_diff to get differents between two object. Of course you can just do array_diff with comparing hash.

    If your data structure is nested like this

    {
      User: {
        FIRSTNAME: 'Irving',
        LASTNAME: 'Block',
        USERID: 150927
      }
      OtherInfo: {
        EMAIL: 'irving.block@email.net'
      }
    }
    

    you can flatten it to following before doing array_diff because array_diff only work on one level.

    {
      "User.FIRSTNAME": 'Irving',
      "User.LASTNAME": 'Block',
      "User.USERID": 150927,
      "OtherInfo.EMAIL": 'irving.block@email.net'
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary

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.