473,786 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Xerces-J does not get the namespace correctly

Hello,
I am not able to read the namespace for my elements correctly. Could
somebody point me to my error. Thank you. Philipp

Compilable example:

import java.io.ByteArr ayInputStream;
import java.io.InputSt ream;
import javax.xml.parse rs.DocumentBuil derFactory;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Ele ment;

public class XMLTest {
public static void main(String[] args) {
String xmlString =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
"<e:test xmlns:e=\"http://www.example.com/e\"/>";

InputStream dataStream = new
ByteArrayInputS tream(xmlString .getBytes());
Document document = null;
try {
document =
DocumentBuilder Factory
.newInstance()
.newDocumentBui lder()
.parse(dataStre am);
} catch (Exception e1) {
e1.printStackTr ace();
}

Element root = document.getDoc umentElement();
System.out.prin tln("prefix: " + root.getPrefix( ));
System.out.prin tln("name: " + root.getNodeNam e() );
System.out.prin tln("localname: " + root.getLocalNa me() );
System.out.prin tln("ns_uri: " + root.getNamespa ceURI());

// PRINTS:
// prefix: null
// name: e:test
// localname: null
// ns_uri: null

// EXPECTED:
// prefix: e
// name: e:test
// localname: test
// ns_uri: http://www.example.com/e
}
}
Jun 27 '08 #1
2 1921
I think you still have to explicitly set Xerces into namespace-aware mode.

http://xerces.apache.org/xerces2-j/features.html
Jun 27 '08 #2
Joseph J. Kesselman wrote:
I think you still have to explicitly set Xerces into namespace-aware mode.

http://xerces.apache.org/xerces2-j/features.html
Thanks. That solved my problem!
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4273
by: bugbear | last post by:
Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards as much as possible, so I'd like to call Xerces under the JAXP API. I'd like to validate the XML against a DTD, so that errors are flagged up to the user, and I can transcribe
2
2719
by: Bekkali Hicham | last post by:
hi, i have downloaded the latest version 2.4 of Xerces, and unziped it, i end up with a diectory hierarchy like this c:\xerces-2_4_0\XercesImpl.jar c:\xerces-2_4_0\XercesSamples.jar c:\xerces-2_4_0\xml-apis.jar c:\xerces-2_4_0\xmlParserAPIS.jar c:\xerces-2_4_0\data c:\xerces-2_4_0\docs c:\xerces-2_4_0\samples there is no bin directory, my question is :
1
11268
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading specs from /usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.1/specs Configured with: ../gcc-3.3.1/configure --disable-nls Thread model: aix gcc version 3.3.1
0
3091
by: Waseem | last post by:
Hi I have looked and tried everything and i still cant sort this out i have no idea why this wont work I am using Xerces Perl on Windows and Debian to try this and it wont work on both of them. Basically i am tryin to do simple tree transversale and get the node values out
4
5611
by: joes | last post by:
Hello there I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing wrong. Could somebody help me? I didn't find any full example working on the net. Thank you for any hints! If I run the examples below, the parsers parses the file well, no vlaidation is occuring although the schema and xml file does not
0
1824
by: Dale Gerdemann | last post by:
I've been trying to use DOM level 3 with xerces-2_6_2. There's a sample called samples/DOM3.java, but I've had trouble with compilation. I've downloaded Xerces-J-bin.2.6.2 and beta2-dom3-Xerces-J-bin.2.6 and added the following paths to my CLASSPATH: ..../xerces-2_6_2/xercesImpl.jar: ..../xerces-2_6_2/dom3-xercesImpl.jar: ..../xerces-2_6_2/dom3-xml-apis.jar: ..../xerces-2_6_2/xmlParserAPIs.jar: ..../xerces-2_6_2/xercesSamples.jar:
3
3405
by: Matt | last post by:
Hello, Summary: Where can one download a Xerces-C (XML pardser) dynamic library file (.DLL file) for Windows (Win98/WinNT/Win2k/WinXP/Win2003, including server flavors; don't need to support pre-98) without having to build the library from source? We posed this question to the Xerces-users email list, but have yet to
3
1942
by: Raphael Tagliani | last post by:
(english version below) Bonjour! Je travaille sur un gros projet java, qui parse beaucoup de fichiers xml au lancement d'un serveur. Nous avons un problème de concurrence qu lancement. En fait, il s'agit d'une erreur Xerces FWK005, et nous sommes incapables de trouver d'où elle provient dans le code. Nous avons déjà essayé de rendre toutes les méthodes qui appellent Xerces synchronized, mais celà
5
2654
by: mearvk | last post by:
Hello, Let me preface this post by saying I'm new to C/C++ and to gcc/g++. Now then, I'm trying to get Xerces (C++) working on a (64-bit) redhat machine. The Xerces binaries were part of the Redhat distribition, and are under /usr/lib64/httpd/.../xerces/ (Apache's stuff right?). Below is the (simple) source file I am trying to compile:
2
2361
by: Boris Kolpackov | last post by:
Hi, I am pleased to announce the availability of Apache Xerces-C++ 3.0.0. Xerces-C++ is an open-source validating XML parser written in a portable subset of C++. It provides DOM (level 1, 2, and 3), SAX, and SAX2 APIs and supports validation of XML documents against DTD and XML Schema. This release includes a large number of new features, bug fixes, and clean-ups, including:
0
9650
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.