Hi,
Using wwConfig.cMode = 'XML'
, just had an issue with JustStem(THIS.cFileName)
beginning with a digit: XML parser rejects a node name beginning with a digit.
text to cXML noshow && (simplified XML)
<?xml version="1.0"?>
<4manufacturing.pjx-awadapter>
<config type="object" class="awadapterpjconfig">
<adaptuser>paul</adaptuser>
<adaptusertest></adaptusertest>
<refreshtest></refreshtest>
<share></share>
</config>
</4manufacturing.pjx-awadapter>
endtext
o = CreateObject('msxml.domdocument')
? o.loadXML(m.cXML) && .F.
? o.parseError.reason && name begins with an invelid character
? o.parseError.line && 2 ('<4manufacturing.pjx-awadapter>')
Here is a suggested workaround (have not seen any dependency on the root node name elsewhere):
PROTECTED FUNCTION CreateXML
…
loXML.cDocRootName = lower(JustStem(THIS.cFileName)) && XML parser rejects a digit as 1rst character of a node name
loXML.cDocRootName = iif(isDigit(loXML.cDocRootName), '_', '') + loXML.cDocRootName && suggestion to add this line
…
A number in a document node is invalid by the XML spec which is why it gets rejected by the parser. It's also illegal for FoxPro variables so this would cause a problem in conversion as well if it is related to an actual child element that maps to a property (which it is not in this case) .
XML Naming Rules
XML elements must follow these naming rules:
- Element names are case-sensitive
- Element names must start with a letter or underscore
- Element names cannot start with the letters
xml
(orXML
, orXml
, etc) - Element names can contain letters, digits, hyphens, underscores, and periods
- Element names cannot contain spaces
Any name can be used, no words are reserved (except xml
).
Your fix works for that specific use case but not if there's any other node that has invalid values. YOu shouldn't be able to create XML like that if you use a valid parser to create the XML.
+++ Rick ---
of course, I'm just addressing the bug of this line:
PROTECTED FUNCTION CreateXML
…
loXML.cDocRootName = lower(JustStem(THIS.cFileName)) && XML parser rejects a digit as 1rst character of a node name
As the file naming and the XML node naming rules differ, you end up with a bug if the file name does not match a node naming rules.
By the way, as the root node's only functionality is to give the document a root node, you could just have (like cursorToXML()
does):
PROTECTED FUNCTION CreateXML
…
loXML.cDocRootName = 'VFPData'
How do you plan to fix this bug?
That'll teach me to not read the whole message 😃
I think this is what we need here based on XML rules:
loXML.cDocRootName = lower(JustStem(THIS.cFileName)) && XML parser rejects a digit as 1rst character of a node name
loXML.cDocRootName = iif( !ISALPHA(loXml.cDocRootName) AND !StartsWith("_"), '_', '') + loXML.cDocRootName && suggestion to add this line
+++ Rick ---