c# - Can't Get .NET XPathNavigator to work -
i having problems xpathnavigator. have document bunch of "topic" elements w/o namespace in stream.
i using (expression dumbed down bare minimum, first thought expressions wrong):
xpathdocument xmldoc = new xpathdocument( stream ); xpathnavigator xml = xmldoc.createnavigator(); xpathnodeiterator iter = xml.select( "//topic" );
this doesn't work. can select */*/*
or similar , "topic" elements alright. tried running expressions in online tester , other languages , work.
question: what's wrong? have lingering suspicion has accursed namespacemanager object, causes me incredible pain every time parse document namespaces, time elements seeking don't have explicit namespace! added:
xmlnamespacemanager s = new xmlnamespacemanager( xml.nametable );
and pass 2nd argument select - no avail. how supposed add "" namespace thing/use correctly?
or, better yet, there way use xpath in .net without using horrible abomination of class, in other languages? if want namespaces, can write them in expression...
update: figured out workaround- copy/paste default xmlns root node, , use namespace:
thisisretarded.addnamespace( "x", "urn:xmind:xmap:xmlns:content:2.0" ); xpathnodeiterator projectiter = projecttree.select( "//x:topic", thisisretarded );
however, neither supposed know default uri, nor pollute expressions unnecessary x:-s. need answer 2nd part of question now.
i prefer use xmldocument
:
xmldocument doc = new xmldocument(); xmlnamespacemanager nsmgr = new xmlnamespacemanager(doc.nametable); nsmgr.addnamespace("sample", "..."); doc.load(stream); xmlnode topic = doc.selectsinglenode("/sample:topic", nsmgr); // if don't have namespaces.... xmlnode topic2 = doc.selectsinglenode("/topic");
Comments
Post a Comment