/// <summary> Create canonical text from a document </summary> public static string Print(AXmlDocument doc) { CanonicalPrintAXmlVisitor visitor = new CanonicalPrintAXmlVisitor(); visitor.VisitDocument(doc); return(visitor.Output); }
public override void VisitDocument(AXmlDocument document) { this.CompilationUnit.ErrorsDuringCompile = document.SyntaxErrors.Any(); this.document = document; base.VisitDocument(document); }
/// <summary> Create XML text from a document </summary> public static string PrettyPrint(AXmlDocument doc) { PrettyPrintAXmlVisitor visitor = new PrettyPrintAXmlVisitor(); visitor.VisitDocument(doc); return(visitor.Output); }
/// <summary> Visit RawDocument </summary> public virtual void VisitDocument(AXmlDocument document) { foreach (AXmlObject child in document.Children) { child.AcceptVisitor(this); } }
/// <summary> Visit RawDocument </summary> public override void VisitDocument(AXmlDocument document) { foreach(AXmlObject child in document.Children) { AXmlTag tag = child as AXmlTag; // Only procssing instructions or elements if (tag != null && tag.IsProcessingInstruction && tag.Name != "xml") { VisitTag(tag); } else if (child is AXmlElement) { VisitElement((AXmlElement)child); } } }
void ClearInternal() { this.UnknownEntityReferenceIsError = true; this.TrackedSegments = new TrackedSegmentCollection(); this.userDocument = new AXmlDocument() { Parser = this }; this.userDocument.Document = this.userDocument; // Track the document this.TrackedSegments.AddParsedObject(this.userDocument, null); this.userDocument.IsCached = false; }
/// <summary> Create new parser </summary> public AXmlParser() { this.UnknownEntityReferenceIsError = true; this.TrackedSegments = new TrackedSegmentCollection(); this.Lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); this.userDocument = new AXmlDocument() { Parser = this }; this.userDocument.Document = this.userDocument; // Track the document this.TrackedSegments.AddParsedObject(this.userDocument, null); this.userDocument.IsCached = false; }
/// <summary> Visit RawDocument </summary> public override void VisitDocument(AXmlDocument document) { foreach (AXmlObject child in document.Children) { AXmlTag tag = child as AXmlTag; // Only procssing instructions or elements if (tag != null && tag.IsProcessingInstruction && tag.Name != "xml") { VisitTag(tag); } else if (child is AXmlElement) { VisitElement((AXmlElement)child); } } }
/// <summary> Raises Changed event </summary> protected void OnChanged() { AXmlParser.Log("Changed {0}", this); if (Changed != null) { Changed(this, new AXmlObjectEventArgs() { Object = this }); } AXmlDocument doc = this.Document; if (doc != null) { doc.OnObjectChanged(this); } // As a convenience, also rasie an event for the parent element AXmlTag me = this as AXmlTag; if (me != null && (me.IsStartOrEmptyTag || me.IsEndTag) && me.Parent is AXmlElement) { me.Parent.OnChanged(); } }
/// <summary> Visit RawDocument </summary> public virtual void VisitDocument(AXmlDocument document) { foreach(AXmlObject child in document.Children) child.AcceptVisitor(this); }
/// <summary> Create canonical text from a document </summary> public static string Print(AXmlDocument doc) { CanonicalPrintAXmlVisitor visitor = new CanonicalPrintAXmlVisitor(); visitor.VisitDocument(doc); return visitor.Output; }
public AXmlDocument ReadDocument() { AXmlDocument doc = new AXmlDocument() { Parser = parser }; // AXmlParser.Log("Flat stream: {0}", PrintObjects(tags)); List <AXmlObject> valid = MatchTags(tags); // AXmlParser.Log("Fixed stream: {0}", PrintObjects(valid)); IEnumerator <AXmlObject> validStream = valid.GetEnumerator(); validStream.MoveNext(); // Move to first while (true) { // End of stream? try { if (validStream.Current == null) { break; } } catch (InvalidCastException) { break; } doc.AddChild(ReadTextOrElement(validStream)); } if (doc.Children.Count > 0) { doc.StartOffset = doc.FirstChild.StartOffset; doc.EndOffset = doc.LastChild.EndOffset; } // Check well formed foreach (AXmlTag xmlDeclaration in doc.Children.OfType <AXmlTag>().Where(t => t.IsProcessingInstruction && t.Name.ToLower() == "xml")) { if (xmlDeclaration.StartOffset != 0) { TagReader.OnSyntaxError(doc, xmlDeclaration.StartOffset, xmlDeclaration.StartOffset + 5, "XML declaration must be at the start of document"); } } int elemCount = doc.Children.OfType <AXmlElement>().Count(); if (elemCount == 0) { TagReader.OnSyntaxError(doc, doc.EndOffset, doc.EndOffset, "Root element is missing"); } if (elemCount > 1) { AXmlElement next = doc.Children.OfType <AXmlElement>().Skip(1).First(); TagReader.OnSyntaxError(doc, next.StartOffset, next.StartOffset, "Only one root element is allowed"); } foreach (AXmlTag tag in doc.Children.OfType <AXmlTag>()) { if (tag.IsCData) { TagReader.OnSyntaxError(doc, tag.StartOffset, tag.EndOffset, "CDATA not allowed in document root"); } } foreach (AXmlText text in doc.Children.OfType <AXmlText>()) { if (!text.ContainsOnlyWhitespace) { TagReader.OnSyntaxError(doc, text.StartOffset, text.EndOffset, "Only whitespace is allowed in document root"); } } AXmlParser.Log("Constructed {0}", doc); trackedSegments.AddParsedObject(doc, null); return(doc); }
/// <summary> Visit RawDocument </summary> public override void VisitDocument(AXmlDocument document) { base.VisitDocument(document); }
/// <summary> Create XML text from a document </summary> public static string PrettyPrint(AXmlDocument doc) { PrettyPrintAXmlVisitor visitor = new PrettyPrintAXmlVisitor(); visitor.VisitDocument(doc); return visitor.Output; }