java - DOM Parser wrong childNodes Count -


this strange let me try best put accross.

i have xml reading through normal way desktop , parsing through dom parser.

<?xml version="1.0" encoding="utf-8"?> <abase     xmlns="www.abc.com/events/abase.xsd">     <fver>0</fver>     <dv>abc app</dv>     <dp>abc wallet</dp>     <dversion>11</dversion>     <sigid>ss22</sigid>     <activity>adding new cake</activity> </abase> 

reading xml childs.

document doc = docbuilder.parse("c://users//desktop//abc.xml"); node root = doc.getelementsbytagname("abase").item(0); nodelist listofnodes = root.getchildnodes();            //sysout prints 13 

so here logic works well.when trying pushing same xml queue , read , child nodes gives me no. of child nodes 6.

document doc=docbuilder.parse(new inputsource(new bytearrayinputstream(msg.getbytes("utf-8")))); node root = doc.getelementsbytagname("abase").item(0); nodelist listofnodes = root.getchildnodes();            //sysout prints 6 

this screws logic of parsing xml.can me out?

update

adding sending logic :

javax.jms.textmessage tmsg = session.createtextmessage(); tmsg.settext(inp); sender.send(tmsg); 

problem if read xml desktop says 13 childs, 6 element node , 7 text nodes.the common logic :

  • read childs , iterate through list of child items.
  • if node isnot text node inside if block,add 1 parent element 2 child , append existing root.then nodename , textcontext between element node , push them settextcontext both childs respectively.
  • so have fresh element node have 2 childs .and dont need existing element node still childs of root,lastly removing them.

so above logic screwed if pushing xml queue , areading doing same logic.

output xml coming when read desktop,but reading queue having problem, because screw complete tree.

<abase     xmlns="www.abc.com/events/abase.xsd"> <prop> <propname>fver</propname> <propname>0</propname> //similarly other nodes </prop> </abase> 

thanks

well, there 13 children if whitespace text nodes included, 6 if whitespace text nodes dropped. there's difference in way tree has been built between 2 cases, affects whether whitespace text nodes retained or not.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -