.net - Read XElement from XmlReader -
i'm playing around parsing xmpp xml stream. tricky thing xml stream start tag not closed until end of session, i.e. complete dom never received.
<stream:stream> <features> <starttls /> </features> .... network session persists arbitrary time .... </stream:stream>
i need read xml elements stream without caring root element has not been closed.
ideally work doesn't , i'm assuming it's because reader waiting root element closed.
xelement someelement = xnode.readfrom(xmlreader) xelement;
the code below (which borrowed jacob reimers) work i'm hoping there more efficient way doesn't involve creating new xmlreader , doing string parsing.
xmlreader stanzareader = xmlreader.readsubtree(); stanzareader.movetocontent(); string outerstanza = stanzareader.readouterxml(); stanzareader.close(); xelement someelement = xelement.parse(outerstanza);
you shouldn't need work strings; should able use xelement.load
on subtree:
xelement someelement; using(xmlreader stanzareader = xmlreader.readsubtree()) { someelement = xelement.load(stanzareader); }
and note isn't "new" xml-reader - heavily tied outer reader (but constrained set of nodes).
Comments
Post a Comment