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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:20:27+00:00 2026-06-06T00:20:27+00:00

Using the elementtree package in nodejs, I’m trying to verify the existence of a

  • 0

Using the elementtree package in nodejs, I’m trying to verify the existence of a certain xml attribute in an xml file (specifically an android manifest file).

var manifestTxt = fs.readFileSync('AndroidManifest.xml', 'utf-8'),
    manifestDoc = new et.ElementTree(et.XML(manifestTxt)),
    expected = 'application/activity[@android:name="com.whatever.app"]';

test.ok(manifestDoc.find(expected));

I’m getting the following exception:

node_modules/elementtree/lib/elementpath.js:210
      throw new SyntaxError(token, 'Invalid attribute predicate');
        ^
Error: Invalid attribute predicate

It doesn’t seem to like the colon in the attribute name, but without it the search doesn’t match. I think I’m handling the namespace wrong — but can’t find the proper way.

Edit Here’s the sample xml I’m searching:

<?xml version='1.0' encoding='utf-8'?>
<manifest ... xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:debuggable="true" android:icon="@drawable/icon" android:label="@string/app_name">&#xA; 
        <activity android:label="@string/app_name" android:name="com.whatever.app">&#xA;                
            <intent-filter>&#xA;</intent-filter>
        </activity> 
    </application>
    <uses-sdk android:minSdkVersion="5" />
</manifest>
  • 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-06T00:20:28+00:00Added an answer on June 6, 2026 at 12:20 am

    Elementtree expects namespace URIs, not namespace prefixes.

    var manifestTxt = fs.readFileSync('AndroidManifest.xml', 'utf-8'),
        manifestDoc = new et.ElementTree(et.XML(manifestTxt)),
        expected = '//application/activity[@{http://schemas.android.com/apk/res/android}name="com.whatever.app"]';
    
    test.ok( manifestDoc.find(expected) );
    

    See: ElementTree: Working with Qualified Names


    Edit The XPath implementation of node-elementtree does not currently seem to have namespace support at all.

    Missing that you’d have to do some legwork:

    var manifestTxt = fs.readFileSync('AndroidManifest.xml', 'utf-8'),
        manifestDoc = new et.ElementTree(et.XML(manifestTxt)),
        activities = manifestDoc.findall('//application/activity'), i;
    
    for (i=0; i<activities.length; i++) {
      if ( activities[i].attrib['android:name'] === 'com.whatever.app' ) {
        test.ok(true);
      }
    }
    

    The line if ( activities[i].attrib['android:name'] === 'com.whatever.app' ) { is largely a guess.

    I don’t know how the parser handles namespaced attributes. When in doubt, just dump the whole activities[i].attrib to the console and see what the parser did. Adapt the above code accordingly. I’m afraid that’s as close as you will get with that kind of limited XPath support.

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

Sidebar

Related Questions

I'm trying to write an xml file with utf-8 encoded data using ElementTree like
What I'm trying to do is simple. Load am XML file using ElementTree so
I am using ElementTree to parse a XML file. In some fields, there will
I have to write an xml file using python standard modules (not using elementtree,
I am using Python's elementtree library to parse an .XML file that I exported
I'm using ElementTree to successfully pull values from specific tags in an xml file.
I'm trying to create XML using the ElementTree object structure in python. It all
I'm parsing an xml file using Python's ElementTree, like that: et = ElementTree(file=file(test.xml)) test.xml
I trying to parse some xml in Google Refine using Jython and ElementTree but
I have been trying to parse a file with xml.etree.ElementTree : import xml.etree.ElementTree as

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.