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 7082851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:06:21+00:00 2026-05-28T07:06:21+00:00

I have an array of xpath values and an xml feed . When the

  • 0

I have an array of xpath values and an xml feed.

When the feed comes in, I want to filter each xml file by removing the nodes that are not in my array of xpath’s.

I can think of a very dirty way to do this:

1) for each node in the xml, i form its xpath

2) check if it’s in the array.

3) if not, remove.

Is there a cleaner way?

  • 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-28T07:06:22+00:00Added an answer on May 28, 2026 at 7:06 am

    When the feed comes in, I want to filter each xml file by removing the
    nodes that are not in my array of xpath’s

    Step1. Select all nodes that aren’t selected by the given XPath expressions

    I guess that by “nodes” you mean elements.
    If so, this XPath expression
    :

    //*[count(. | yourExpr1 | yourExpr2 ... | yourExprN)
       >
        count(yourExpr1 | yourExpr2 ... | yourExprN)
       ]
    

    selects all elements in the XML document that aren’t selected by any of your N XPath expressions yourExpr1, yourExpr2, … , yourExprN

    If by “nodes” you mean elements, text-nodes, processing-instruction-nodes (PIs), comment-nodes and attribute nodes, use this XPath expression to select all nodes not selected by your N XPath expressions:

    (//node() | //*/@*)
       [count(. | yourExpr1 | yourExpr2 ... | yourExprN)
       >
        count(yourExpr1 | yourExpr2 ... | yourExprN)
       ]
    

    Step2. Delete all nodes selected in Step1.

    For each of the nodes selected in Step1 above, use:

     node.ParentNode.RemoveChild(node);
    

    Explanation:

    1. The XPath union operator | produces the union of two node-sets. Therefore the expression yourExpr1 | yourExpr2 ... | yourExprN when applied on the XML document produces the set of all nodes that are selected by any of the N given XPath expressions.

    2. A node $n doesn’t belong to a set of nodes $ns exactly when
      …

      count($n | $ns) > count($ns)

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

Sidebar

Related Questions

I have an method that reads an xml file and stores the xml nodes
I have some reference data in a text file (~5MB) that I want to
I have an xml file that looks like this <step> <id>3</id> <backid>1</backid> <question>Are you
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I have an array of numbers that potentially have up to 8 decimal places
So I have a PHP file that I use to define all my constants
Here is an example bit from the xml file: <array> <dict> <key>Name</key> <string>Joe Smith</string>
I have a XML file like this: <Document> <Tests> <Test> <Name>A</Name> <Value>1</Value> </Test> <Test>
I have a small XML file: <wddxPacket version='1.0'> <header/> <data> <struct type='coldfusion.runtime.ArgumentCollection'> <var name='HEADLINE'>
I have an XML file structured like this <serieslist> <series sid=123> <title type=main>Series 123

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.