Thank you, now this is my code, how i can add the Namespace to the
Document, i ithink this is my last Problem:
Document doc = null;
Namespace ns = new
Namespace("test","http://swt.informatik.uni-mannheim.de/2007/BomberManLevel");
SAXReader reader = new SAXReader();
try{
doc = reader.read("Example_Level.xml");
}catch(DocumentException e){
System.err.println("Level-Datei konnte nicht gelesen werden");
}
Node node =
doc.selectSingleNode("/test:level/test:size/test:width");
if(doc != null){
Element element = (Element) node;
String text = element.getText();
System.out.println("Width: " + text);
}
Nichiketa s schrieb:
> Add a Name space
> "http://swt.informatik.uni-mannheim.de/2007/BomberManLevel" to the
> call. Give it a name like "test" and when doing an selectSingle Node
> add name space as below and you should see the result
>
> "/test:level/test:size/test:width"
>
> - H
>
>> From: Felix Schlenkrich <[EMAIL PROTECTED]>
>> To: [email protected]
>> Subject: Re: [dom4j-user] Problem with Namespace?
>> Date: Sat, 07 Apr 2007 18:55:57 +0200
>>
>> Hi,
>>
>> iÂŽm checking if doc is null, because of the try-block, if the file is
>> not read i donÂŽt need the code in the the if-clause. but youÂŽre right,
>> this is not the problem.
>>
>> sorry for my english, it is not good enough.
>>
>> greetings
>>
>> Meltsner, Kenneth schrieb:
>> >
>> > Not sure why you're checking whether doc is null after you run the
>> > selectSingleNode(), but that's not your problem...
>> >
>> > -----Original Message-----
>> > From: [EMAIL PROTECTED]
>> > <[EMAIL PROTECTED]>
>> > To: [email protected]
>> <[email protected]>
>> > Sent: Sat Apr 07 06:23:36 2007
>> > Subject: [dom4j-user] Problem with Namespace?
>> >
>> > Hello,
>> >
>> > iÂŽm have to parse an XML-Data which describes a level for a game, i
>> > think i have problems with the namespace.
>> >
>> > My code:
>> >
>> > Document doc = null;
>> > SAXReader reader = new SAXReader();
>> > try{
>> > doc = reader.read("Example_Level.xml");
>> > }catch(DocumentException e){
>> > System.err.println("Level-Datei konnte nicht gelesen werden");
>> > }
>> > Node node = doc.selectSingleNode("/level/size/width");
>> > if(doc != null){
>> > Element element = (Element) node;
>> > String text = element.getText();
>> > System.out.println("Width: " + text);
>> > }
>> >
>> >
>> > The line 'String text = element.getText();' throws a
>> > NullPointerException, i think because the Node is null.
>> >
>> > A part of the XML-File:
>> >
>> > <?xml version="1.0" encoding="UTF-8"?>
>> > <level
>> xmlns="http://swt.informatik.uni-mannheim.de/2007/BomberManLevel"
>> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> >
>> xsi:schemaLocation="http://swt.informatik.uni-mannheim.de/2007/BomberManLevel
>>
>>
>> > BombermanLevel.xsd ">
>> > <creator>Daniel Brenner</creator>
>> > <date>2007-03-20</date>
>> > <size>
>> > <width>16</width>
>> > <height>16</height>
>> > </size> .............
>> >
>> > Does anyone see the mistake i make?
>> >
>> > Greetz Felix
>> >
>> >
>> -------------------------------------------------------------------------
>>
>> > Take Surveys. Earn Cash. Influence the Future of IT
>> > Join SourceForge.net's Techsay panel and you'll get the chance to
>> > share your
>> > opinions on IT & business topics through brief surveys-and earn cash
>> >
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>
>> >
>> <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>
>>
>> > _______________________________________________
>> > dom4j-user mailing list
>> > [email protected]
>> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
>> >
>>
>>
>> -------------------------------------------------------------------------
>>
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to
>> share your
>> opinions on IT & business topics through brief surveys-and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>
>> _______________________________________________
>> dom4j-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
> _________________________________________________________________
> Get a FREE Web site, company branded e-mail and more from Microsoft
> Office Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-user