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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:54:07+00:00 2026-05-26T07:54:07+00:00

I have realized a really stupid xPath filter in MatLab: % Construct the DOM.

  • 0

I have realized a really stupid xPath filter in MatLab:

% Construct the DOM.
docNode = xmlread('C:\Users\MATLAB\test.gpx');

% get the xpath mechanism into the workspace
import javax.xml.xpath.*
factory = XPathFactory.newInstance;
xpath = factory.newXPath;

% compile and evaluate the XPath Expression
expression = xpath.compile('gpx/AddressBook/Entry/PhoneNumber');
phoneNumberNode = expression.evaluate(docNode, XPathConstants.NODE);
phoneNumber = phoneNumberNode.getTextContent

With this XML (specifically a .gpx file) it works:

<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
<gpx version='1.1' creator='TTTracklog V.1.13'>
    <AddressBook>
       <Entry>
          <Name>Friendly J. Mathworker</Name>
          <PhoneNumber>(508) 647-7000</PhoneNumber>
          <Address hasZip="no" type="work">3 Apple Hill Dr, Natick MA</Address>
       </Entry>
    </AddressBook>
</gpx>

and text (508) 647-7000 is returned.
Simply adding xmlns attribute to gpx node in this way:

<?xml version='1.0' encoding='ISO-8859-1' standalone='yes' ?>
<gpx version='1.1' creator='TTTracklog V.1.13'  xmlns='http://www.topografix.com/GPX/1/1'>
    <AddressBook>
       <Entry>
          <Name>Friendly J. Mathworker</Name>
          <PhoneNumber>(508) 647-7000</PhoneNumber>
          <Address hasZip="no" type="work">3 Apple Hill Dr, Natick MA</Address>
       </Entry>
    </AddressBook>
</gpx>

gave me error, and matlab report:

??? Attempt to reference field of non-structure array.

Error in ==> test at 12 phoneNumber = phoneNumberNode.getTextContent

Why? How can I avoid that error?

  • 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-26T07:54:07+00:00Added an answer on May 26, 2026 at 7:54 am

    Dabbler’s comment above is correct. Since you have added a default namespace to your XML document, you must also alter your XPath expression to search for nodes in your new default namespace.

    Unqualified names in XPath expressions (like AddressBook) are in the null XML namespace, not the default XML namespace of your document.

    So you want to somehow register your new namespace with your xpath object. Like:

    {"foo": "http://www.topografix.com/GPX/1/1"}
    

    and then alter your XPath expression to:

    foo:gpx/foo:AddressBook/foo:Entry/foo:PhoneNumber
    

    There are docs on how to do this with the javax.xml.xpath API here:

    http://www.ibm.com/developerworks/library/x-javaxpathapi/index.html#N1022D

    However, I’m not sure how this translates to Matlab, exactly.

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

Sidebar

Related Questions

Okay, I've realized that I really have asked way too many questions without contributing
Say we have realized a value of TDD too late. Project is already matured,
EDIT: I have realized the source of my problem. I only have count information
I have a website which uses Spring Security. I have realized that when I
I decided to teach myself assembly language. I have realized that my program will
I realized that I can have problems with single quotes in php arrays: <?php
I realized today that I have blindly just followed this requirement for years without
Today I realized that I no longer have a Web Content Form option (where
I just realized that in some place in my code I have the return
I've creating a Java Swing application and I realized that I have many many

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.