Capricornph
2015-09-09 08:28
采纳率: 60%
浏览 3.1k

asp 如何读取xml元素内容

请教一下各位大大 如何读取xml中的元素内容呢

 Set myxml=Server.CreateObject("Microsoft.XMLDOM")
    myxml.load(Server.MapPath("test.xml"))
Set myroot=myxml.documentElement.selectSingleNode("DocBody")
Dim lenth:lenth=myroot.childNodes.length'节点数
For i=0 To lenth-1
  Response.Write(myroot.childNodes.item(i).text)
Next

set myroot=nothing
set myxml=nothing 

xml内容

 <?xml version="1.0" encoding="GBK"?>
<EmrDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost:8080/sys/schemas/EmrDoc2.xsd">
  <DocHeader>
    <DocInfo>
      <DocID></DocID>
      <DocTypeID>34106</DocTypeID>
      <DocTitle></DocTitle>
      <DocTime>2015-09-06T11:55:39.000000</DocTime>
      <ModifyTime>2015-09-06T11:55:39.000000</ModifyTime>
      <DocSetID></DocSetID>
      <DocVersion>1</DocVersion>
      <SignCode/>
      <ConfidCode/>
    </DocInfo>
    <AuthorInfo>
      <CreatorID></CreatorID>
      <CreatorName></CreatorName>
      <CreatorDeptCode></CreatorDeptCode>
      <CreatorDeptName></CreatorDeptName>
      <ModifierID></ModifierID>
      <ModifierName></ModifierName>
      <ModifierDeptCode></ModifierDeptCode>
      <ModifierDeptName></ModifierDeptName>
    </AuthorInfo>
    <PatientInfo>
      <PatientID></PatientID>
      <PatientName></PatientName>
      <GenderCode>1</GenderCode>
      <Gender>男</Gender>
      <BirthTime></BirthTime>
      <BirthPlace></BirthPlace>
      <MaritalCode>2</MaritalCode>
      <Marital>已婚</Marital>
      <FamilyAddr></FamilyAddr>
      <Department></Department>
      <OccupationCode/>
      <Occupation/>
      <RaceCode>01</RaceCode>
      <RaceName>汉族</RaceName>
    </PatientInfo>
    <VisitInfo>
      <VisitID>12</VisitID>
      <InpID></InpID>
      <VisitTime>2015-08-05T11:28:12.000000</VisitTime>
      <VisitType>IP</VisitType>
      <BedCode>31</BedCode>
      <DeptCode></DeptCode>
      <DeptName></DeptName>
      <WardCode></WardCode>
      <WardName></WardName>
      <CareCode></CareCode>
      <CareName></CareName>
    </VisitInfo>
  </DocHeader>
  <DocBody>
    <Text></Text>
    <Text>名</Text>
    <fieldelem name="" code="1000000984.1.20110512145321.7462" code-system="LONIC"></fieldelem>
    <Text>性 别</Text>
    <fieldelem name="" code="1000000985.1.20110512145322.2031" code-system=""></fieldelem>
    <Text>年龄</Text>
    <fieldelem name="" code="1000000987.1.20110512145323.3984" code-system=""></fieldelem>
    <Text>职业</Text>
    <fieldelem name="" code="1000000992.1.20110512145326.3537" code-system="LONIC"></fieldelem>
    <Text></Text>
    <fieldelem name="日期" code="2000000035.1.20110512145325.4475" code-system="LONIC"></fieldelem>
    <Text></Text>
    <Text></Text>
    <fieldelem name="数值" code="1000000416.1.20110512145308.3567" code-system="LONIC">12</fieldelem>
    <Text></Text>
    <Text></Text>
    <fieldelem name="日期" code="2000000035.1.20110512145325.4475" code-system="LONIC"></fieldelem>
    <Text></Text>
    <fieldelem name="数值" code="1000000416.1.20110512145308.3567" code-system="LONIC">33</fieldelem>
    <Text>天</Text>
    <Text/>

    <Text>                </Text>
    <fieldelem name="" code="1000000981.1.20110512145319.5716" code-system="LONIC"></fieldelem>
    <Text/>
    <Text/>
    <fieldelem name="yyyy年M月d日 HH:mm" code="1000001104.1.20110512145316.6196" code-system="">2015-09-07,07:28</fieldelem>
  </DocBody>
</EmrDoc>

想显示DocBody元素中的所有内容 这个要如何操作呢?非常感谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 已采纳

    直接输出docbody的xml属性,不过不太明白你要干嘛。。,你不是取出所有的节点的内容了?还是连属性值一起输出?

    Set myroot=myxml.documentElement.selectSingleNode("DocBody")
    
    response.Write myroot.xml
    
    
    Dim lenth:lenth=myroot.childNodes.length'节点数
    For i=0 To lenth-1
        set node=myroot.childNodes.item(i)
      Response.Write(node.text)&"<br>"
        if node.tagname="fieldelem" then 
    
          response.Write node.getAttribute("code")&" "&node.getAttribute("code")&" "&node.getAttribute("code-system")&"<br>"
        end if
    
    Next
    
    
    打赏 评论
  • threenewbee 2015-09-09 08:29
    打赏 评论

相关推荐 更多相似问题