protected void ParseContent(StringStream stream) { if (stream.GetChar() == LEFTBRACE) { // Node content if (stream.IsNext(ENDNODE)) { // End node stream.ExtractUntil(true, RIGHTBRACE); // Skip to end return; } else if (stream.IsNext(COMMENT)) { // Comment stream.ExtractUntil(ENDCOMMENT, true); } else { XMLNode subNode = new XMLNode(this); if (!subNode.Parse(stream)) { // Error parsing. Stop return; } Add(subNode); } } else { // Text content Content = stream.ExtractUntil(false, LEFTBRACE); } // Parse rest of content ParseContent(stream); }
/* * Returns whether node has sub-content */ protected bool ParseAttributes(StringStream stream) { string str = stream.ExtractUntil(false, EQUALS, SLASH, RIGHTBRACE); switch (stream.ExtractChar()) { // An attribute case EQUALS: // Treating attributes as subnodes with text content XMLNode attr = new XMLNode(this); attr.Key = str; attr.Content = stream.ExtractBetween(QUOTE, QUOTE); Add(attr); // Parse more attributes return(ParseAttributes(stream)); // End of attributes, no content case SLASH: stream.ExtractUntil(true, RIGHTBRACE); // Remove right brace return(false); // End of attributes, with content case RIGHTBRACE: default: return(true); } }
public bool Parse(StringStream stream) { try { stream.ExtractChar(); //remove startbrace // Get Name Key = stream.ExtractUntil(false, '\n', '\t', ' ', RIGHTBRACE); // Parse content if (ParseAttributes(stream)) { ParseContent(stream); } return(true); } catch (Exception ex) { BigBoss.Debug.w(Logs.XML, "Exception while parsing node: " + this + " " + ex); return(false); } }