필터 지우기
필터 지우기

register a namespace in xPath filter

조회 수: 7 (최근 30일)
marianoc84
marianoc84 2011년 10월 15일
댓글: Jarrod Rivituso 2013년 11월 7일
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
sst
sst 2013년 11월 4일
편집: sst 2013년 11월 4일
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 2013년 11월 7일
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!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Structured Data and XML Documents에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by