我在解析XML
文件时发现了一个问题
这是XML 文件的示例(作为字符串):
<ns:fetchXmlResponse xmlns:ns=\ " http: / ws.src.com \>
<ns:return>
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<TemplateData>
<TemplatePrescriptionData>
<id>24</id>
<noOfRefills>1</noOfRefills>
<templateId>67</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Norco</prescriptionName>
<prescriptionStrength>5/325</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1-2tabs po q4-6 hours, prn
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>15</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>25</id>
<noOfRefills>2</noOfRefills>
<templateId>67</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Motrin
</prescriptionName>
<prescriptionStrength>600</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1tab po q6 hours,
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>28</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>26</id>
<noOfRefills>2</noOfRefills>
<templateId>67</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Chlorhexidine</prescriptionName>
<prescriptionStrength>0.12</prescriptionStrength>
<prescriptionUnit>%</prescriptionUnit>
<prescriptionForm>Mouth
</prescriptionForm>
<prescriptionSignature>rinse mouth bid
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>1</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>28</id>
<noOfRefills>1</noOfRefills>
<templateId>76</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Norco</prescriptionName>
<prescriptionStrength>5/325</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1-2tabs po q4-6 hours, prn
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>15</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>30</id>
<noOfRefills>2</noOfRefills>
<templateId>76</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Motrin
</prescriptionName>
<prescriptionStrength>600</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1tab po q6 hours,prn
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>28</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>31</id>
<noOfRefills>2</noOfRefills>
<templateId>76</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Chlorhexidine</prescriptionName>
<prescriptionStrength>0.12</prescriptionStrength>
<prescriptionUnit>%</prescriptionUnit>
<prescriptionForm>MouthRinse
</prescriptionForm>
<prescriptionSignature>rinse mouth bid(withexpectoration)
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>1</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>32</id>
<noOfRefills>1</noOfRefills>
<templateId>79</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Norco</prescriptionName>
<prescriptionStrength>5/325</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1-2tabs po q4-6 hours, prn</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>15</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>33</id>
<noOfRefills>2</noOfRefills>
<templateId>79</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Motrin
</prescriptionName>
<prescriptionStrength>600</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1tab po q6 hours,prn</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>28</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
</TemplateData>
</ns:return>
</ns:fetchXmlResponse>
代码:
var xmlDoc=loadXMLString(Above XML file);
//Then i'm fetching "ns:return" node(Which is also an XML file)
var returnNode = String(xmlDoc.getElementsByTagName("ns:return")[0].childNodes[0].nodeValue);
loadXMLString函数
function loadXMLString(txt)
{
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(txt,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(txt);
}
现在的问题是returnNode
变量只有4048
字符,尽管整个 xmlfile
样本:
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<TemplateData>
<TemplatePrescriptionData>
<id>24</id>
<noOfRefills>1</noOfRefills>
<templateId>67</templateId>
<templatePrescriptionMaintainanceId>0</templatePrescriptionMaintainanceId>
<prescriptionName>Norco</prescriptionName>
<prescriptionStrength>5/325</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1-2 tabs po q4-6 hours, prn
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>15</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>25</id>
<noOfRefills>2</noOfRefills>
<templateId>67</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Motrin </prescriptionName>
<prescriptionStrength>600</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1 tab po q6 hours, prn</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>28</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>26</id>
<noOfRefills>2</noOfRefills>
<templateId>67</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Chlorhexidine</prescriptionName>
<prescriptionStrength>0.12</prescriptionStrength>
<prescriptionUnit>%</prescriptionUnit>
<prescriptionForm>Mouth Rinse</prescriptionForm>
<prescriptionSignature>rinse mouth bid (with expectoration)
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>1</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>28</id>
<noOfRefills>1</noOfRefills>
<templateId>76</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Norco</prescriptionName>
<prescriptionStrength>5/325</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1-2 tabs po q4-6 hours, prn
</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>15</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>30</id>
<noOfRefills>2</noOfRefills>
<templateId>76</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Motrin </prescriptionName>
<prescriptionStrength>600</prescriptionStrength>
<prescriptionUnit>mg</prescriptionUnit>
<prescriptionForm>Tablet(s)</prescriptionForm>
<prescriptionSignature>1 tab po q6 hours, prn</prescriptionSignature>
<prescriptionWarnings></prescriptionWarnings>
<prescriptionComments></prescriptionComments>
<prescriptionQuantity>28</prescriptionQuantity>
<statusCode>true</statusCode>
<createDate>2009-07-22T00:00:00+05:30</createDate>
<updateDate>2009-07-22T00:00:00+05:30</updateDate>
</TemplatePrescriptionData>
<TemplatePrescriptionData>
<id>31</id>
<noOfRefills>2</noOfRefills>
<templateId>76</templateId>
<templatePrescriptionMaintainanceId>0
</templatePrescriptionMaintainanceId>
<prescriptionName>Chlorhexidine</prescriptionName>
<prescriptionStrength>0.12</prescriptionStrength>
<prescriptionUnit>%</prescriptionUnit>
<prescriptionForm>Mouth Rinse</prescriptionForm>
<prescriptionSignature>rinse mouth bid (with expectoration)
</pr
注意:我已经尝试过,jQuery
但首先它会验证数据并引发Invalid XML
异常。
我还验证了它"The processing instruction target matching "[xX][mM][lL]" is not allowed."
在我的文件中显示的这个文件。
谁能帮我解决这个问题,或者你能建议我一些棘手的方法来处理这种类型的 XML 文件吗?