2013-06-09 4 views
0

누구나 xml을 vbscript로 구문 분석하는 예제가 있습니까? .NET generic 목록을 XML로 직렬화하여 고전 ASP 페이지로 보냅니다. XMLDom을 사용할 수있을 것이라고 생각했지만 라이브러리가 서버에 설치되어 있지 않은 것처럼 보였으므로 다른 솔루션을 찾고 있습니다. ("Object Required : documentElement"오류가 발생했습니다.)xml을 vbscript로 구문 분석

기본적으로 제목과 주요 기사 섹션이 포함 된 xml 문자열 형태로 약 15 개의 개체 목록을 전달하고 있습니다. 목록을 작성하고 둘 다 인쇄하십시오.

것은 이것은 내가 XMLDOM가 설치되지 않은 발견하기 전에 내가 가진 무엇 이었습니까 :

set xmlDoc=CreateObject("Microsoft.XMLDOM") 
xmlDoc.async="false" 
xmlDoc.loadXML(item) 

Set objFirstChild = xmlDoc.documentElement.firstChild 
Set objAttributes = objFirstChild.attributes 
For Each Attr in objAttributes 
    Response.write(Attr.Headline & "<br>") 
    Response.write(Attr.Content & "<br>") 
Next 
Response.End 

어떤 도움을 주시면 감사 - 내 VBScript를 요즘 꽤 녹슨입니다!

편집 - MSXML2.DOMDocument으로 시도했지만 Object Required 오류가 발생했습니다.

<?xml version="1.0" encoding="utf-8"?> 
<articles> 
    <article> 
    <newsID>7</newsID> 
    <headline>This is headline 1</headline> 
    <content><![CDATA[<p>This is the start of the main content of the article</p><p>This is the next paragraph.</p> ]]></content> 
    <date>04/06/2013 00:00</date> 
    </article> 
    <article> 
    <newsID>7</newsID> 
    <headline>This is headline 2</headline> 
    <content><![CDATA[<p>This is the start of the main content of the article</p><p>This is the next paragraph.</p> ]]></content> 
    <date>04/06/2013 00:00</date> 
    </article> 
    <article> 
    <newsID>7</newsID> 
    <headline>This is headline 3</headline> 
    <content><![CDATA[<p>This is the start of the main content of the article</p><p>This is the next paragraph.</p> ]]></content> 
    <date>04/06/2013 00:00</date> 
    </article> 
</articles> 
+0

XML을 게시 할 수 있습니까? – ulluoink

+0

xmldom이 "설치되지 않은 경우"createobject ("...") 행에서 오류가 발생합니다. – ulluoink

+0

안녕하세요 ulluoink - 샘플 xml로 게시물을 수정했습니다. 불행히도 저는 코드가 어디에 있지 않으므로 복사본이 아니기 때문에 xml이 어떻게 배치되어 있는지를 알 수 있습니다. –

답변

1

AFAIK는 객체 속성 Headline 또는 Content이없는 속성 : -

UPDATE 샘플 XML은 @ulluoink의 요청에 포함되어 있습니다. 자식 노드의 HeadlineContent 속성 값을 쓰려고합니까? 이를 위해 다음과 같은 것이 필요합니다 :

For Each attr In objAttributes 
    If attr.Name = "Headline" Or attr.Name = "Content" Then 
    response.write attr.Value & "<br>" 
    End If 
Next 
1

일반적으로 오류/가능성 검사없이 DOM 메소드를 사용하지 마십시오. XML로 시작하는 '분석'에 대한 최소한의 골격은 입력에 적용 :

Dim sFSpec : sFSpec = resolvePath("..\data\17014567.xml") 
    Dim oXDoc : Set oXDoc = CreateObject("Msxml2.DOMDocument") 
    oXDoc.setProperty "SelectionLanguage", "XPath" 
    oXDoc.async = False 
    oXDoc.load sFSpec 

    If 0 = oXDoc.ParseError Then 
    WScript.Echo sFSpec, "looks ok" 
    ' ? Set objFirstChild = xmlDoc.documentElement.firstChild 
    Dim X : Set X = oXDoc.documentElement.firstChild 
    WScript.Echo 0, TypeName(X), X.tagName 
    ' ? Set objAttributes = objFirstChild.attributes 
    Set X = X.attributes 
    WScript.Echo 1, TypeName(X), X.length 
    If 0 < X.length Then 
     Dim Attr 
     For Each Attr in X 
      ' ? Attr.Headline, Attr.Content 
     Next 
    Else 
     WScript.Echo 2, "no attributes!" 
    End If 
    Else 
    WScript.Echo oXDoc.ParseError.Reason 
    End If 

출력 :

E:\trials\SoTrials\answers\8194209\data\17014567.xml looks ok 
0 IXMLDOMElement article 
1 IXMLDOMNamedNodeMap 0 
2 no attributes! 

명확하게 루프를 통해 어떤 속성이 아니라는 것을 보여.