I'm having all sorts of fun trying read snippets into a Narrative. The problem lies in the fact that the list is going to be heterogeneous. If I knew that the next element was going to be a snippet, I could just move to the next snippet. But it could be a choice, an image ... There doesn't seem to be a way to move to first child node as in a DOM walking solutions.
So I think I'm going to have to approach this from a lower level. I found this to be an interesting exercise:
import System
import System.IO
import System.Xml
src = """
<wibble>
<wobble> a </wobble>
<wobble> b </wobble>
<woo foo="bar"> c </woo>
</wibble>
"""
r = XmlReader.Create(StringReader(src))
while r.Read():
if r.NodeType == XmlNodeType.Whitespace:
continue;
if r.NodeType == XmlNodeType.Element:
print "Element: ${r.Name}"
continue
print r.NodeType
When run, that yields
Element: wibble
Element: wobble
Text
EndElement
Element: wobble
Text
EndElement
Element: woo
Text
EndElement
EndElement
So that's probably enough information to solve the problem. I just need to do a bit more work...
No comments:
Post a Comment