Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XPath Namespace AXL -> leere nodes

Empfohlene Antworten

Hallo,

habe ein kleines Problem in Java. Ich sitze gerade an einem kleinen XPath Parser für AXL (das Sprachelement vom Cisco Unified Call Manager 6) Ergebnisse, welche in einer XML-Datei abgespeichert werden.

Mein Problem sind höchstwahrscheinlich die Namespaces. Also erstmal brauche ich über XPath diese Elemente (Pfad speichere ich in einer Variable):

	private static final String XPATH_DEV_NAME = "/SOAP-ENV:Envelope/SOAP-ENV:Body/axl:executeSQLQueryResponse/return/row/name/text()";

private static final String XPATH_DEV_DESC = "/SOAP-ENV:Envelope/SOAP-ENV:Body/axl:executeSQLQueryResponse/return/row/description/text()";

Im späteren Verlauf versuche ich den Namespace zu deklarieren sprich:
	private static void xpath_connection(String file)

			throws ParserConfigurationException, SAXException, IOException,

			XPathExpressionException {

		DocumentBuilderFactory domFactory = DocumentBuilderFactory

				.newInstance();

		domFactory.setNamespaceAware(true);

		DocumentBuilder builder = domFactory.newDocumentBuilder();

		doc = builder.parse(file);

		XPathFactory factory = XPathFactory.newInstance();

		xpath = factory.newXPath();

		xpath.setNamespaceContext(ns);

	}


	private static NamespaceContext ns = new NamespaceContext() {

		@Override

		public String getNamespaceURI(String prefix) {

			String uri = null;

			if (prefix.equals("SOAP-ENV")) {

				uri = "http://schemas.xmlsoap.org/soap/envelope";

			} else if (prefix.equals("axl")) {

				uri = "http://www.cisco.com/AXL/API/7.0";

			}

			return uri;

		}


		@Override

		public String getPrefix(String namespaceURI) {

			// TODO Auto-generated method stub

			return null;

		}


		@Override

		public Iterator getPrefixes(String namespaceURI) {

			// TODO Auto-generated method stub

			return null;

		}

	};

Aber irgendwie liefert er mir dann nur noch leere Nodes, was meiner Meinung nach an dem Namespace (also genauer dem ":") liegt. Restlicher Quelltext funktioniert, wurde so aus einer anderen Anwendung komplett übernommen, die läuft.

Meine Frage nun, wie könnte ich dieses Problem beheben und/oder umgehen?

Vielen Dank vorab für eure Kooperation.

Mfg

Christian, 20, K.

Hallo,

habe dieses Problem nun unschön behoben:

	//Entfernt das "SOAP-ENV:" sowie das "axl:" welches zu Problemen führte.

	// http://www.geocities.com/eric6930/findreplace.html

	public static void readReplace(String fname, String oldPattern, String replPattern){

		String line;

		StringBuffer sb = new StringBuffer();

		try {

			FileInputStream fis = new FileInputStream(fname);

			BufferedReader reader=new BufferedReader ( new InputStreamReader(fis));

			while((line = reader.readLine()) != null) {

				line = line.replaceAll(oldPattern, replPattern);

				sb.append(line+"\n");

			}

			reader.close();

			BufferedWriter out=new BufferedWriter ( new FileWriter(fname));

			out.write(sb.toString());

			out.close();

		}

		catch (Throwable e) {

		            System.err.println("*** exception ***");

		}

	}

Mfg

Christian, 20, K.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.