java - Finding XML Tags by Namespace URI -


i seem having problems doing basic parsing of xml document in java. trying retrieve list of tags based on specific namespace. unfortunately, list of tags returned empty. can enlighten me doing wrong? thanks.

example java

documentbuilder bob = documentbuilderfactory.newinstance().newdocumentbuilder(); document template = bob.parse( new inputsource( new filereader( xmlfile ) ) ); nodelist tags = template.getelementsbytagnamens( "http://www.example.com/schema/v1_0_0", "*" ); 

example xhtml

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"     xmlns:ex="http://www.example.com/schema/v1_0_0">     <head><title>test</title></head>     <body>         <h1>test</h1>         <p>hello, world!</p>         <p><ex:test>text</ex:test></p>     </body> </html> 

you need create documentbuilder such aware of namespaces prior trying parsing things namespace. i.e.:

documentbuilderfactory dbf = documentbuilderfactory.newinstance(); dbf.setnamespaceaware(true);     documentbuilder bob = dbf.newdocumentbuilder();  

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -