Effacer les filtres
Effacer les filtres

register a namespace in xPath filter

1 vue (au cours des 30 derniers jours)
marianoc84
marianoc84 le 15 Oct 2011
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'>
<Entry>
<Name>Friendly J. Mathworker</Name>
<PhoneNumber>(508) 647-7000</PhoneNumber>
<Address hasZip="no" type="work">3 Apple Hill Dr, Natick MA</Address>
</Entry>
</gpx>
but as soon add a namespace to this file I get in trouble. For example, this xml doesn't works:
<?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' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>
<Entry>
<Name>Friendly J. Mathworker</Name>
<PhoneNumber>(508) 647-7000</PhoneNumber>
<Address hasZip="no" type="work">3 Apple Hill Dr, Natick MA</Address>
</Entry>
</gpx>
My filter broke up, with second XML file, saying that I'm attempting to reference field of non-structure array. How can I register the default namespace?
  2 commentaires
sst
sst le 4 Nov 2013
Modifié(e) : sst le 4 Nov 2013
Hello marianoc84, I am also looking for a solution to a similar problem. Do let me know if you find anything.
Jarrod Rivituso
Jarrod Rivituso le 7 Nov 2013
I'm not sure how do do this without really getting into the Java files. :)
There's a tool I put together which allows you to extract data via XPath with namespace support.
You may find it useful!

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by