Skip to content

Commit

Permalink
IsValid (XML RelaxNG) now takes xml strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsn committed Aug 28, 2012
1 parent e8a9cb9 commit f386448
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions vvvv45/src/nodes/plugins/XML/XMLNodeWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ public void Evaluate(int spreadMax)
}


[PluginInfo(Name = "Validate", Category = "XML RelaxNG")]
[PluginInfo(Name = "IsValid", Category = "XML RelaxNG")]
public class RelaxNGValidateNode : IPluginEvaluate
{
[Input("Xml File", StringType = StringType.Filename, FileMask = "XML (*.xml)|*.xml")]
public IDiffSpread<string> XmlFile;
[Input("Xml String")]
public IDiffSpread<string> Xml;

[Input("Rng File", StringType = StringType.Filename, FileMask = "RNC (*.rnc)|*.rnc|RNG (*.rng)|*rng")]
public IDiffSpread<string> RngFile;
Expand All @@ -381,14 +381,14 @@ public class RelaxNGValidateNode : IPluginEvaluate

public void Evaluate(int spreadMax)
{
if (!XmlFile.IsChanged && !RngFile.IsChanged) return;
if (!Xml.IsChanged && !RngFile.IsChanged) return;

Message.SliceCount = spreadMax;
Valid.SliceCount = spreadMax;

for (int i = 0; i < spreadMax; i++)
{
var message = XMLNodes.RelaxNGValidate(XmlFile[i], RngFile[i]);
var message = XMLNodes.RelaxNGValidate(Xml[i], RngFile[i]);
Message[i] = message;
Valid[i] = message == "";
}
Expand Down
9 changes: 5 additions & 4 deletions vvvv45/src/nodes/plugins/XML/XMLNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ public static string AsString(this XElement element)
}

[Node]
public static string RelaxNGValidate(string xmlFile, string rngFile)
public static string RelaxNGValidate(string xml, string rngFile)
{
string r = "\r\n";

// Files must exist.
if (!File.Exists(xmlFile))
return "Source file not found.";
if (!File.Exists(rngFile))
return "Schema file not found.";

Expand Down Expand Up @@ -211,8 +209,11 @@ public static string RelaxNGValidate(string xmlFile, string rngFile)
else
return "Unknown schema file extension: " + Path.GetExtension(rngFile);

byte[] byteArray = Encoding.ASCII.GetBytes(xml);
MemoryStream stream = new MemoryStream(byteArray);

// Validate instance.
XmlTextReader xtrXml = new XmlTextReader(xmlFile);
XmlTextReader xtrXml = new XmlTextReader(stream);
RelaxngValidatingReader vr = new RelaxngValidatingReader(xtrXml, p);
try
{
Expand Down

0 comments on commit f386448

Please sign in to comment.