xml node attributes are automatically being converted to lower case
Hi,
I am new to hacking javascript and this forum.
I am trying to build a jsTree engine that parses an XML file, allows the user to modify the attribute values and then write this back to the server.
I have building the function across several different scripts to get a understanding if what's going on.
I am currently having an issue with the case of an attribute when I break out my xml node list. It always seems to be automatically set to lowercase.
On the w3schools site I found this property styles.textTransform = "none", but I cant seem to apply it, in the correct place (see comments for where I tried).
Is this what I should be using?
I have attached my example code, it should be a complete example. It should produce an output that looks like the following,
Starting here
.OBJECTS.PGEXE1.REF.enablecomms="0"
.OBJECTS.PGEXE1.REF.objtype="pglite"
.OBJECTS.PGEXE1.REF.objects tate="initial"
.OBJECTS.PGEXE1.REF.startups leep="10"
.OBJECTS.PGEXE1.REF.COMMAND.targetid="1"
......
.OBJECTS.PGEXE1.REF.COMMAND.COMMS.STATUSREBOOT.pgcontroller=""
.OBJECTS.PGEXE1.REF.COMMAND.COMMS.STATUSREBOOT.rebootcount="0"
.OBJECTS.PGEXE1.REF.COMMAND.COMMS.STATUSREBOOT.rebootenable="1"
.OBJECTS.PGEXE1.REF.COMMAND.COMMS.STATUSREBOOT.rebootthreshold="3"
.OBJECTS.PGEXE1.REF.COMMAND.COMMS.STATUSREBOOT.reboottimeout="0"
Ending here
I am using Chrome as my browser, is there a way I can search all the properties of the xml2 variable, using the inbuilt debugging features?
thanks
a
HTML Code:
<!doctype html>
<html lang="en" >
<head>
<title> xmlUnroller</title>
<meta charset="utf-8" >
<link rel="stylesheet" href="tabs.css" >
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" > </script>
</head>
<body>
<script>
var xml2 = '<root> <objects> <pgExe1> <REF enablecomms="0" objType="pglite" objectState="initial" startupSleep="10" > <command TargetId="1" buoyId="001" dspExePath="../v2.13/pg_dsp.out" exeName="pg_gpp" path="../v2.13/" scriptName="shPgLite.exe" xmlPath="../pbXmlConfigs/pb-xxx-20120913_135459.xml" /> <comms enable="0" host="localhost" maxlength="1024" port="1999" proto="udp" status="0" timeout="5" /> <statusReboot pgController="" rebootCount="0" rebootEnable="1" rebootThreshold="3" rebootTimeout="0" /> </REF> </pgExe1> </objects> </root> ';
var html = [];
function traverse(tree, printString) {
$(tree).contents().each(function() {
printString = printString + '.' + this.nodeName;
//html.push(this.nodeType + this.nodeName + '<br> ');
if (this.nodeType == 3) { // text node
html.push('---'+$(this).text()+ '<br> ');
} else {
if (this.nodeType == 2) { // attribute node
// node value: $(this).text() or this.nodeValue
//html.push('<br> ');
html.push('+++'+$(this).attr()+ '<br> ');
} else {
if(this.attributes.length > 0){
//html.push('==='+this.nodeName + ': ' + this.attributes.length + ' ~ <br> ');
for( var iCnt = 0; iCnt < this.attributes.length; iCnt++){
//this.attributes[iCnt].nodeName.styles.textTransform = "none";
//this.textTransform = "none";
//html.push(printString + iCnt + ' ' + this.attributes[iCnt].nodeName + ' ' + this.attributes[iCnt].nodeValue + ' ~ <br>');
html.push(printString + '.' + this.attributes[iCnt].nodeName + '="' + this.attributes[iCnt].nodeValue + '"<br>');
}
}
traverse(this, printString);
}
}
});
}
function createPage(obj) {
html.push('Starting here');
html.push('<br>');
//xml2.styles.textTransform = "none";
traverse(xml2, '');
html.push('<br>Ending here');
html.push('<br>');
$('body').append(html.join(""));
}
window.onload = createPage();
</script>
</body>
</html>
I appear to have solved this by actually treating the string as XML. I am not sure how it was being treated before
Code:
function createPage(obj) {
html.push('Starting here');
html.push('<br>');
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(xml2,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(xml2);
}
traverse(xmlDoc, '');
html.push('<br>Ending here');
html.push('<br>');
$('body').append(html.join(""));
}
The output looks much better
.root.objects.pgExe1.REF.enablecomms="0"
.root.objects.pgExe1.REF.objType="pglite"
.root.objects.pgExe1.REF.objectState="initial"
.root.objects.pgExe1.REF.startupSleep="10"
.root.objects.pgExe1.REF.command.TargetId="1"
.root.objects.pgExe1.REF.command.buoyId="001"
.root.objects.pgExe1.REF.command.dspExePath="../v2.13/pg_dsp.out"
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks