将xml文件加载到变量中

时间:2015-05-18 22:00:32

标签: javascript xml

我有一个xml格式,我需要加载到一个变量,最初我直接有xml输入,但做php问题我在一个单独的文件中有.xml。

Originally


            var labelXml = '<xml version="1.0" encoding="utf-8">\
            <DieCutLabel Version="8.0" Units="twips">\
            <PaperOrientation>Landscape</PaperOrientation>\
            <Id>Address</Id>\
            <PaperName>30252 Address</PaperName>\
            <DrawCommands>\
            <RoundRectangle X="0" Y="0" Width="1581" Height="5040" Rx="270" Ry="270"/>\
            </DrawCommands>\
            <ObjectInfo>\
            <BarcodeObject>\
            <Name>BARCODE</Name>\
            <ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>\
            <BackColor Alpha="255" Red="255" Green="255" Blue="255"/>\
            <LinkedObjectName></LinkedObjectName>\
            <Rotation>Rotation0</Rotation>\
            <IsMirrored>False</IsMirrored>\
            <IsVariable>False</IsVariable>\
            <Text>*E200001*</Text>\
            <Type>Code39</Type>\
            <Size>Medium</Size>\
            <TextPosition>Bottom</TextPosition>\
            <TextFont Family="Lucida Grande" Size="10" Bold="False" Italic="False" Underline="False" Strikeout="False"/>\
            <CheckSumFont Family="Lucida Grande" Size="10" Bold="False" Italic="False" Underline="False" Strikeout="False"/>\
            <TextEmbedding>None</TextEmbedding>\
            <ECLevel>0</ECLevel>\
            <HorizontalAlignment>Center</HorizontalAlignment>\
            <QuietZonesPadding Left="0" Right="0" Top="0" Bottom="0"/>\
            </BarcodeObject>\
            <Bounds X="331.2" Y="328.0469" Width="4455.625" Height="1044.844"/>\
            </ObjectInfo>\
            </DieCutLabel>';

现在我拥有的是

var labelXml = loadXMLDoc("barcode.xml");

但是,由于浏览器不兼容,我收到错误“loadxmldoc is undefined”。那么有没有人知道将.xml加载到变量的方法,以便它与原始格式具有相同的格式?

 function loadXMLDoc(filename)
  {
  if (window.XMLHttpRequest)
    {
    xhttp=new XMLHttpRequest();
    }
  else // code for IE5 and IE6
    {
    xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xhttp.open("GET",filename,false);
  xhttp.send();
  return xhttp.responseXML;
  } 

0 个答案:

没有答案