7.3 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T02:55:32.255842+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | efe0fd52c00cf697 |
XMLUtils
Documentation: DTS.Common.XMLUtils Module
1. Purpose
This module provides utility functions for parsing, extracting, and aggregating XML metadata from DTS test files. It supports reading attribute values from XML files (e.g., TotalItems), extracting inner XML content from an XmlReader, and consolidating multiple .dts XML test files into a unified XDocument structure for downstream processing (e.g., test execution or reporting). The module exists to abstract low-level XML handling logic and ensure consistent parsing behavior across the codebase.
2. Public Interface
DTSXMLFile.GetItemsToCompleteCount(string fileName)
public static double GetItemsToCompleteCount(string fileName)
- Behavior: Loads the XML node from
fileNameusingFileUtils.GetImportXmlNode, then extracts theTotalItemsattribute value as adouble. Returns0.0if the attribute is missing, invalid, or any exception occurs during parsing. - Note: Uses
CultureInfo.InvariantCulturefor conversion.
DTSXMLFile.GetInnerXML(XmlReader reader)
public static string GetInnerXML(XmlReader reader)
- Behavior: Reads the current element’s inner XML text content. Assumes the reader is positioned on the start element. Advances the reader past the end element. Returns the text value of the element (or empty string if none). Throws
ArgumentExceptionifreaderisnull. - Implementation details:
- Calls
reader.ReadStartElement(reader.Name)to consume the start element. - Reads
reader.Value(which may be empty for non-text nodes). - If the current node is
XmlNodeType.Text, advances once more. - Calls
reader.ReadEndElement()to consume the end element.
- Calls
TestMetadataXml.GetTestMetadataXml(string path, string file = "", string pattern = "")
public static XDocument GetTestMetadataXml(string path, string file = "", string pattern = "")
- Behavior: Populates
FileUtils.FileListwith files matchingpattern(default".dts") underpath, or adds a singlefileif provided. Then callsSetTestMetadataTypeto process the list and return a consolidatedXDocument. - Output structure:
<Tests> <TestMetadata Id="0"> <Test DataType="ALL|ROI" FilePath="..." FileDate="..." ... /> <!-- or --> <TestSetup ... /> </TestMetadata> ... </Tests> - Error handling: Logs exceptions per-file via
APILogger.Logand continues processing remaining files. Returns an emptyXDocumenton total failure.
TestMetadataXml.SetTestMetadataType(IEnumerable<string> fileList) (private)
private static XDocument SetTestMetadataType(IEnumerable<string> fileList)
- Behavior: Core logic for aggregating XML content from
fileList. For each file:- Reads entire file content as string.
- Splits content on
"<?xml version="to handle multiple XML declarations in one file. - For each XML fragment:
- Loads into
XDocument. - If
<Test>element exists: addsDataType("ALL"if filename contains"ALL", else"ROI"),FilePath, andFileDate(creation time) as attributes. - Adds
<Test>or<TestSetup>element to a new<TestMetadata>container (with auto-incrementedIdattribute).
- Loads into
- Aggregates all
<TestMetadata>elements under root<Tests>.
3. Invariants
-
DTSXMLFile.GetItemsToCompleteCount:- Returns
0.0for any failure (missing file, invalid XML, missing/invalidTotalItemsattribute). - Does not validate XML structure beyond attribute extraction.
- Returns
-
DTSXMLFile.GetInnerXML:- Requires the
XmlReaderto be positioned on a start element (e.g., afterRead()orReadStartElement()). - Always advances the reader past the end element.
- Does not handle nested elements or mixed content; only returns the immediate text value (
reader.Value).
- Requires the
-
TestMetadataXml.GetTestMetadataXml/SetTestMetadataType:FileUtils.FileListis mutated as a side effect (overwritten with the processed file list).DataTypeis determined solely by whether the filename contains"ALL"(case-sensitive).FileDateusesFile.GetCreationTime(file)(system-dependent; may be unreliable on some platforms).- XML fragments in a single file must be well-formed when prefixed with
"<?xml version=".
4. Dependencies
Internal Dependencies
DTS.Common.Utils.FileUtils:- Used for
FileUtils.GetImportXmlNode(inGetItemsToCompleteCount). - Used for
FileUtils.FileList(static field) andFileUtils.FindFiles(inGetTestMetadataXml).
- Used for
DTS.Common.Utilities.Logging.APILogger:- Used for logging exceptions in
SetTestMetadataType.
- Used for logging exceptions in
System Dependencies
System.Xml,System.Xml.Linq,System.IO,System.Globalization.
Depended Upon
- Likely consumed by test orchestration, reporting, or validation modules (not evident from source).
5. Gotchas
-
GetItemsToCompleteCount:- Swallows all exceptions silently—no logging or differentiation between error types.
- Assumes
FileUtils.GetImportXmlNodereturns a non-null node; if it returnsnull,node.GetAttribute(...)will throwNullReferenceException(caught and returns0.0).
-
GetInnerXML:- Uses
reader.Value, which may be empty for elements with child nodes (e.g.,<elem><child/></elem>→Value = ""). Does not return full inner XML (despite the name). - Assumes the element has no mixed content; text after child elements would be missed.
- Uses
-
TestMetadataXml:- Critical: Splits XML content on
"<?xml version="—if the XML contains this string within content (e.g., in a comment or attribute), it will be incorrectly split. FileDateusesFile.GetCreationTime, which is not guaranteed to be accurate (e.g., filesystem behavior varies; may reflect copy time, not original creation).Idis a simple counter (count++), not derived from file content—order-dependent and non-deterministic across runs if file order changes.- No deduplication: if a file contains multiple
<Test>elements, they are added as separate<Test>children under the same<TestMetadata>. - No validation of XML structure beyond checking for
<Test>or<TestSetup>root elements.
- Critical: Splits XML content on
-
NullableElement<T>:ValuethrowsInvalidOperationExceptionif accessed whenHasValue == false.GetValueOrDefault()returns the default value ofT(e.g.,0forint,nullfor reference types) if no value exists—this may be ambiguous ifTitself is nullable.- The
explicit operator Tmay cause unexpected exceptions if used on an empty instance.
-
General:
- No thread-safety guarantees (static fields like
FileUtils.FileListare shared). SuppressMessageonDTSXMLFileindicates intentional deviation from naming conventions (acronym "DTS" preserved).
- No thread-safety guarantees (static fields like
Documentation generated from provided source files. No behavior inferred beyond explicit code.