0

We are developing some DevOps module which reads/parses/cleanup some markup files and other artifacts. There is no need of validations to be performed against existing.

As part of above, we are trying to read few existing vue.js templates which have attribute prefixes as just "colon". It is a valid syntax according to vue.js. Unfortunately, we are not able to load that markup using c#.

I have following markup, which is valid according to vue.js:

<div class="form-group">
    <AppCodeDropDownList :activityCode="activity.ActivityCode" 
        :activitySubcode="activity.ActivitySubCode" :mode="mode" 
        v-on:activity-code-selection="onActivityCodeSelection" 
        v-on:activity-subcode-selection="onActivitySubCodeSelection">
    </AppCodeDropDownList>
</div>

I used XML reader as following:

XmlReaderSettings xrs = new XmlReaderSettings();
xrs.CheckCharacters = false;
xrs.ConformanceLevel = ConformanceLevel.Document;
xrs.ValidationType = ValidationType.None;
xrs.DtdProcessing = DtdProcessing.Ignore;
xrs.IgnoreComments = true;
xrs.IgnoreProcessingInstructions = true;
xrs.IgnoreWhitespace = true;

using (var reader = XmlReader.Create(sourceFile, xrs))
{
    while (reader.Read())...

It throws an error

Name cannot begin with the ':' character, hexadecimal value 0x3A'.

In simple terms, imagine that I would like to read the above markup, do some "process" on each of the nodes, and write back similar kind of markup to some other file.

Any suggestions?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user203687
  • 6,875
  • 12
  • 53
  • 85
  • maybe vue.js is wrong about this? – Marc Gravell Oct 01 '18 at 21:56
  • 2
    It's not valid XML. Looks like a null namespace or something. You would at least need a preprocessor. – H H Oct 01 '18 at 21:56
  • I mean you could swap ‚:‘ with something like ‚a:‘ (where ‚a‘ is unique), then do the processing and strip the a from the XML. But this is really a quick and dirty approach – charL Oct 01 '18 at 22:00
  • It's not XML, don't try to parse it as such. One option is to parse as HTML though, [HtmlAgilityPack](https://www.nuget.org/packages/HtmlAgilityPack/) should load this fine and allow you to manipulate it. – DavidG Oct 01 '18 at 22:30
  • Several users have suggested that this is not valid XML, but I'm not so sure about that... https://stackoverflow.com/questions/40445735/is-a-colon-a-legal-first-character-in-an-xml-tag-name – rutter Oct 01 '18 at 22:59
  • @rutter - do read the answer under that question. – bommelding Oct 04 '18 at 10:38
  • @bommelding The one that says XML parsers should accept colons in names? Yeah, I did. – rutter Oct 04 '18 at 15:42
  • You should read that a little better (past the first paragraph). – bommelding Oct 05 '18 at 06:39

0 Answers0