Reputation: 737
I am backing up all files from the client's computer to a server. After each file is backed up, I create or update a record in a XML file. My problem is, occasionally the string used to create or find a node contains an invalid token. The string used to create or find the node is determined by the folder path and file name of the file that was backed up.
Example:
File backed up: C:\users\Jon_Doe\Desktop\Report.doc
XML File:
<root>
<Jon_Doe>
<Desktop>
<Report LastBackup="12/17/2014 11:51:10" />
</Desktop>
</Jon_Doe>
</root>
If I encounter a string that contains any of the following char characters { ' ' , ',' , '(' , ')' }
, I remove it from the string. But I cannot determine what is wrong with the string "64bitPrereq".
How can I determine what part of the string is the 'Invalid Token' before using the string to find or create a node?
Upvotes: 2
Views: 887
Reputation: 122364
I cannot determine what is wrong with the string "64bitPrereq"
XML does not allow element names that begin with an ASCII digit. Names can contain digits, dots and hyphens after the first character, but must begin with a letter or underscore (the exact rules are slightly more complicated than that, see the XML specification if you care about non-Latin characters).
For this kind of task it would make much more sense to use a fixed element name and store the file or folder name as an attribute, rather than trying to make the folder name into the element name itself, e.g.
<root>
<Folder name="Jon_Doe">
<Folder name="Desktop">
<File name="Report" LastBackup="12/17/2014 11:51:10" />
</Folder>
</Folder>
</root>
Upvotes: 2