Skip to content

Commit

Permalink
comment out <xref> elements which have no or an invalid @target
Browse files Browse the repository at this point in the history
  • Loading branch information
SerdoSchofield committed May 1, 2019
1 parent 6580fc6 commit 9de295d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions MultiTermTBXConverter/ConverterApplication.cs
Expand Up @@ -1688,6 +1688,35 @@ private void addNameSpace(XmlNode currentNode)
//multiTermDoc.DocumentElement.SetAttribute("xmlns", "urn:iso:std:iso:30042:ed:3.0");
}

private void checkXrefs()
{
XmlNodeList xrefs = multiTermDoc.SelectNodes("//xref");
foreach (XmlNode xref in xrefs.AsParallel())
{
if (xref.Attributes?["target"] != null)
{
string target = xref.Attributes["target"].Value;

if (!Regex.IsMatch(target, "^https?://"))
{
commentifyNode(xref);
}
}
else
{
commentifyNode(xref);
}
}
}

private void commentifyNode(XmlNode node)
{
string commentContent = node.OuterXml;
XmlComment xmlComment = multiTermDoc.CreateComment(commentContent);
XmlNode parent = node.ParentNode;
parent.ReplaceChild(xmlComment, node);
}

private void convertXML(FileStream xmlData, string outputPath, LevelOneClass initialJSON, string tbxOutputDialect, string errorPath)
{
XmlReaderSettings readerSettings = new XmlReaderSettings();
Expand Down Expand Up @@ -1730,6 +1759,9 @@ private void convertXML(FileStream xmlData, string outputPath, LevelOneClass ini
// Correct ordering of elements
correctOrdering();

// Comment out <xref> elts with invalid target values
checkXrefs();

// Recursively remove built up white space
removeWhitespaceChildren(multiTermDoc);

Expand Down

0 comments on commit 9de295d

Please sign in to comment.