XPath /A/B/C/@a works, but /A/A/A/@a doesn't ...
I get XPath values for simple XML files without problems (element values or attribute values). Now I have an XML file where a quite simple XPath doesn't work:
<?xml version="1.0" encoding="UTF-8" ?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time="2005-06-15">
<Cube currency="USD" rate="1.2069" />
</Cube>
</Cube>
</gesmes:Envelope>The XPaths "/gesmes:Envelope/Cube/Cube/@time" or "//Cube/Cube/@time" don't work. I notice that the element names of different hierarchies are the same so I built a similar XML with distinguished element names and there my xpath works. Alas, the XML file is the source that I can't change. So is there another way to state an XPath to get the time value?
I use this code:
* Get value of the node specified by an XPath.
* @param item The starting context (e.g. document, node, node list).
* @param xPath XPath to select single node value (e.g. "/root/data/value[1]/text()")
* @return Result of <i>xPath</i> (the node's value) or null if failed.
* @throws XPathExpressionException if <i>xPath</i> is wrong.
static public String getXPathValue(Object item, String xPath) throws XPathExpressionException {
String result = null;
if (item != null && xPath != null) {
try {
result = XPathFactory.newInstance().newXPath().evaluate(xPath, item);
} catch (NullPointerException npe) {
//XPathFactory.newInstance() throws NullPointerException when called from ActiveX bean
if (item instanceof Document) {
result = getXPathValueApache((Document) item, xPath);
// if (ICUtils.isEmptyString(result)) {
// XPath xp = XPathFactory.newInstance().newXPath();
// xp.setNamespaceContext(new javax.xml.namespace.NamespaceContext () {
// public String getNamespaceURI (String prefix) {
// if (prefix.equals("rsp")) {
// return "http://schemas.xmlsoap.org/soap/envelope/";
// else if (prefix.equals(javax.xml.XMLConstants.XML_NS_PREFIX)) {
// return javax.xml.XMLConstants.XML_NS_URI;
// else if (prefix.equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) {
// return javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
// else {
// return javax.xml.XMLConstants.NULL_NS_URI;
// public String getPrefix (String namespaceURI) {
// if (namespaceURI.equals(javax.xml.XMLConstants. "http://schemas.xmlsoap.org/soap/envelope/")) {
// return "rsp";
// else if (namespaceURI.equals(javax.xml.XMLConstants.XML_NS_URI)) {
// return javax.xml.XMLConstants.XML_NS_PREFIX;
// else if (namespaceURI.equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
// return javax.xml.XMLConstants.XMLNS_ATTRIBUTE;
// else {
// return null;
// public Iterator getPrefixes (String namespaceURI) {
// // not implemented for the example
// return null;
// result = xp.evaluate(xPath, item);
//workaround for non working XPaths of SOAP messages:
if (ICUtils.isEmptyString(result) && item instanceof Document) {
//some XPaths for SOAP Messages don't work with Java API:
String r = getXPathValueApache((Document) item, xPath);
if (!ICUtils.isEmptyString(r)) {
result = r;
}//else: input values not available
return result;
}//getXPathValue()
* Get value of the node specified by an XPath.
* @param document Document to get node value of.
* @param xPath XPath to select single node value (e.g. "/root/data/value[1]/text()")
* @return Result of <i>xPath</i> (the node's value) or null if failed.
* @throws org.w3c.dom.xpath.XPathException if XPath result object is not of type XPathResult.
* @see <a href="http://www.w3schools.com/xpath/default.asp">XPath Tutorial</a>
static private String getXPathValueApache(Document document, String xPath) throws org.w3c.dom.xpath.XPathException {
String result = null;
if (document != null && xPath != null) {
org.w3c.dom.xpath.XPathEvaluator evaluator = new org.apache.xpath.domapi.XPathEvaluatorImpl(document);
Object o = evaluator.evaluate(xPath, document, evaluator.createNSResolver(document), org.w3c.dom.xpath.XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (o != null) {
if (o instanceof org.w3c.dom.xpath.XPathResult) {
org.w3c.dom.xpath.XPathResult xpResult = (org.w3c.dom.xpath.XPathResult) o;
Node node = xpResult.getSingleNodeValue();
if (node != null) {
result = node.getNodeValue();
} else {
throw new org.w3c.dom.xpath.XPathException(org.w3c.dom.xpath.XPathException.TYPE_ERR, "XPath '"+xPath+"' didn't return an object of type XPathResult!");
}//else: no result for XPath
}//else: input values not available
return result;
}//getXPathValue()and it works well with "normal" XML files (distinguished element names) and also to get element attribute values. But for this specific XML (posted above), the XPaths don't work.
Similar Messages
-
I have an iphone 5 and my Siri doesn't work at the moment. But when I restart my phone it works but 5 minutes later it doesn't work again!!! What should I do???
Try reset iPad
Hold down the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears
Note: Data will not be affected. -
I have a Ipod mini 6gb that still works but a new computer that doesn't have its software. How can I download the software for it
Check the iPod Hardisk health with the iPod Disk Diagnostic, as posted by tt2
https://discussions.apple.com/message/17776595#17776595
It wont fix your problem, but may tell help troubleshoot, why it is freezing iTunes, especially when the Pending and Realloc numbers are high.
have a nice day! -
Dear all,
some times ago I had problems in copying cell contents from ALV reports. java gui 7.10 rev 6 solved the issue but....
... I still cannot paste it in SAPGUI.
I mean:
- I can paste it in other OSX application (like textedit)
- I cannot paste it in an input field of sapgui
to copy/paste from sapgui to sapgui I have to copy from sapgui, paste it to textedit, copy from textedit and paste it into sapgui.
No problem if I copy the value from a "normal" field. The only issue is if I copy from ALV reports.
Any hint?
Lorenzo
My gui:
SAPGUI for Java 7.10 rev 6
(Version ID 071000040600)
Tue Sep 2 16:17:38 MEST 2008
uw1059, 710_REL, 1009179
Java VM: Apple Inc. Version 1.5.0_16
OS: Mac OS X(i386) Version 10.5.5Hello Lorenzo,
this sounds like a bug we have fixed recently (assuming that I get your description correctly).
The forthcoming SAP GUI for Java 7.10 rev 7 should solve the issue.
Best regards
Rolf-Martin
Update: The version is now [available|ANN: SAP GUI for Java 7.10 rev 7 available for download;.
Edited by: Rolf-Martin Woersinger on Dec 12, 2008 11:26 AM -
HELP ME PLEASE! My SWF movie works but as a GIF it doesn´t works
Hi, Could you help me with this problem? I have many movie clips inside the scene1 and I know that ´s the problem. But I don´t know how should I start a new animation using just one layer and keyframe to do easier the export in a gif format.THANKS!
Hi Jelle van Blokland,
Here is an article that has troubleshooting for Wi-Fi connections in iOS, including disconnecting:
iOS: Troubleshooting Wi-Fi networks and connections
http://support.apple.com/kb/ts1398
Cheers!
- Ari -
MAMP home page works, but my own PHP file doesn't.
MAMP 1.7.2 is working oddly. I just installed it and the homepage works fine at the default address:
http://localhost:8888/MAMP/?language=English
However when I create a "hello, world" foo.php in the MAMP/test directory and load it with this URL:
http://localhost:8888/MAMP/test/foo.php
I get a page not found error.
Same with an .html file.
My sole clue: the file /Applications/MAMP/logs/apacheerrorlog contains this line:
[Fri Oct 10 16:29:50 2008] [error] [client ::1] File does not exist: /Applications/MAMP/bin/mamp/foo
Not clear to me why it expects the /bin/mamp extra directories.
And /Applications/MAMP/conf/apache/httpd.conf has this line, which seems right:
DocumentRoot "/Applications/MAMP/htdocs"
Any ideas why HTML and PHP files don't work?
Rig:
MAMP 1.7.2
Apache port: 8888
MySQL port: 8889
MacBook Air 1.6 Ghz Core 2 Duo
OS/X 10.5.5
2G RAM
80G hard disk, 50G freeActually I do know something, because it(url address) above does work on my Panther MAMP to load bs.php & bs.html files out of htdocs. And start page loads fine.
-
My AX is working but my Windows 7 laptop doesn't recognize the network
My network is through a Verizon DSL modem and a LinkSys wireless router on the top floor of a 3-story house, where there is a Mac in use. Coverage extends to the 2nd story, but not to the first, so wanted an extender. The AX was recommended as better than others at the same price. I downoaded the AX Utility on my Windows 7 laptop, plugged in the AX near the stairwell on the 2nd floor, and configured to join the existing network. Light is green, utility says all is well, but there is only the pre-existing network on my wireless network list, and again it doesn't extend to the 1st floor, so the existing network goes dead as I descend the stairs and there is no other network showing up. Should there be a new network appearing as broadcast from the AX? Did I not configure it correctly? Do I need to configure the utility from the Mac? Any help would be appreciated.
I have Airport Express Model no. A1264, firmware version 7.6, everything looks good, but no internet through the AX
-
When I make a date reservation from the Iphone or GoogleAgenda it appears in ICal.
When I make an appointment in ICal in doesn't show up in the Iphone and GoogleAgenda.
Does somebody know how to solve this problem ?Refer to this article under section 4: Verify that the Apple Mobile Device USB Driver is installed
iOS: Device not recognized in iTunes for Windows
http://support.apple.com/kb/TS1538 -
Can some one tell me if there is an easymule for mac. I have downloaded one, but it is not working. There is a amule, it works, but very slow.
Sniper Elite doesn't have a release for Macintosh as far as i know. It was only released on Windows and other gaming consoles, but not on Mac OS X.
-
I am unable to open my Photoshop program after installing the entire Creative Suite: Premium Production 6. All other programs work, but with Photoshop it says that it "Could not open a scratch file because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the 'Properties' command in the Windows Explorer to unlock the file." Then I select "OK" and the next message comes up "Could not initialize Photoshop because the file is locked, you do not have the necessary permissions, or another program is using the file. Use the 'Properties' command in the Windows Explorer to unlock this file. I installed all of the programs on the same day from a CD. I need this fixed immediately.
I am not interested in switching to Creative Cloud, so don't even suggest it. I spoke to Mashmi (or something to that effect) on the "Support" Chat and there was absolutely no support. Useless actually.
Thanks in advance.Could not open a scratch file because the file is locked or you do not have the necessary access privileges. (…) | Mylen…
Mylenium -
Report works but not when scheduling
Hi,
I have a report that copies table contents to a text file. When using this report from se38 everything works but every time we schedule the job from sm36 it gets status cancelled.
The input to the report is what table should be copied and where it should be copied to.
The error message is from sm36 job scheduling is: "Could not ascertain code page"
Message class: FES
What does this mean?
regards
BaranWhere do you download the text file to?
If you try to save to your PC, it will never work.
You can not download to a local drive, only to UNIX or print the file to the spool. Then, later, you'll need to retrieve it either from UNIX or from the spool. -
hi can any one help i want to get the new ipad for work but i need to print.i see i can buy a usb connector can i print if i plug my printer into the usb.
If you have a USB printer connected to your computer, Mac or PC, you can activate or install AirPrint and print from your iPad over wifi without any special apps.
Activate AirPrint in Mac OS X;
http://netputing.com/airprintactivator/
Add AirPrint to Windows;
http://jaxov.com/2010/11/how-to-enable-airprint-service-on-windows/ -
When I first got my phone it worked perfectly fine with the wifi. Although later on I began to have problems connecting it. It will randomly disconnect from the wifi and when I try to retype the password it tells me it is wrong, although it is right. It will eventually work but in its own time, a message will pop up and allow me to type in the password and it will work. But sometimes it takes an hour or more and sometime it takes 10 minutes. I've seen where other people have had this problem but I don't know how to fix it. I'm not sure if it's an issue with my phone or if it's with my wifi. Does anyone know how to fix this?
Does this happen with all Wi-Fi hotspots? A specific one?
Have you tried forgetting the Wi-Fi connection and then reconnecting to it?
What about power cycling the Wi-Fi router? -
Why iPhone 6 Plus sound microphone not working, but in the case of sound recordings in conversation mode work?
Sighhhh, wasted so much time yesterday and today going around Sony centre and then carphone warehouse. They told me to come back after Easter.
I came home, banged the phone against the wall and it worked.
Turned out that mic was working on loud speaker and when using headphones so I thought that the secondary mic is working and the main one (placed with the speakers) isn't. So I banged that part against the wall slightly (in plastic case to prevent scratches) then put the phone underwater, waited for it to dry and now it's working. Idk how well and if it's of perfect quality again but people can hear me well. -
How do I change my user name in syn? I typed in the wrong email address. And I cancelled syn thinking this may work but no luck.
You have to clear saved password for this page:
# Open you login page (where you have to enter username and password).
# Right click on page and select '''Page Info''' form context menu.
# On last tab ('''Security''') there is '''View saved passwords''' button, click it and delete all saved passwords for this page.
# Also clear all related cookies (just in case) there is button for this next to first one.
Maybe you are looking for
-
My iPhone 4S appears to be using an old Apple ID and keeps asking for my sign in. How can I change this to my current ID -this applied to iCloud only.
-
Incase Dual Car USB Charger with Lightning to USB Cable
Hi, I just buy this item and it seems that the item is not working... What can i do? Incase Dual Car USB Charger with Lightning to USB Cable $39.95 Yakir
-
How do I get my library to share across a home network?
I was at college, and I could connect to several other people's iTunes libraries, and they could connect to mine. Now that I am back at home, I wanted to be able to access my library on other computers (both Macs and PCs) throughout my house...but it
-
Matching up between pdf and indesign
How can I match up a table chart in an indesin file with the one in the pdf to check if there's any error on the indesign one? (which would be like proofreading done by a computer) The design of each table chart is totally different from each other;
-
Is Adobe CS4 compatable with a mac 10.5.8?
I'm having troubles opening up Ai with my Mac 10.5.8. I open it and click File>New and the screen is still blank with occasional pop-ups about "plug-ins." Not quite sure what to do. Should I uninstall?