?
Solved

Microsoft.XMLDOM in asp - get arbitrary nodes

Posted on 2004-11-23
5
Medium Priority
?
773 Views
Last Modified: 2012-06-27
I'm trying to do this in asp, iis5, win2k:

SET objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load("\\casablanca\Public\changemark.xml")
'objXML.loadXML(BinaryBuffer) 'can i load a binary xml stream directly into the xml object?
                  
SET Node = objXML.documentElement.selectSingleNode("Text/TextLine")
IF LEN (Node.Text) > 0 THEN
     Response.Write " " & Node.Text & " "
END IF
SET Node = NOTHING : SET objXML = NOTHING

I have 3 problems:

(1) the code breaks on the "SET Node" line with "Object required: 'objXML.documentElement'"
(2) the snippet i'm using, if it did work, doesn't do quite what i want. i just found the snippet online. I need to be able to parse an xml document and extract the text/values from any and all occurrances of <TextLine>.
(3) which version of the xmldom dll should i use? i know there are a few. it must work "out of the box" on win2k, xp and win2003. i'm using what i think is the oldest version to ensure that it works on vanilla win2k os. But maybe there's a newer version that comes with win2k.

. . .my xml file looks like this:

 <?xml version="1.0" encoding="UTF-8" ?>
- <IGCMarkupDocument xmlns="http://www.somedomain.com" revision="4" majorversion="0" minorversion="0">
- <PageList pagecount="1">
- <Page index="0">
- <AuthorList authorcount="1">
- <Author name="johne">
- <Text id="0" time="1100715019" color="255,0,0" fontsize="1.60284" italic="false" bold="false" opaque="false" underline="false" font="Arial" hyperlink="">
-  <TextLine>text on drawing in markup</TextLine>
  </Text>
- <Changemark id="1" time="1100715030" color="255,0,0" hyperlink="">
  <Title>Description of changemark, for john</Title>
  <Comment>This is the details of the changemarks for Johns Changemark</Comment>
- <Viewstate Extents="true">
  <Page>0</Page>
  <ScaleFactor>1.44467</ScaleFactor>
  <Rotation>0.0</Rotation>
- <EyePoint>
  <x>367.5</x>
  <y>244.0</y>
  </EyePoint>
- <DeviceRect>
  <top>0</top>
  <left>0</left>
  <bottom>706</bottom>
  <right>1157</right>
  </DeviceRect>
- <LayerTable LayerCount="1">
  <LayerBlock>1</LayerBlock>
  </LayerTable>
  </Viewstate>
  </Changemark>
  </Author>
  </AuthorList>
  </Page>
  </PageList>
  </IGCMarkupDocument>

0
Comment
Question by:SweatCoder
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 12661973
If you can lose the namespace as in:

<?xml version="1.0" encoding="UTF-8" ?>
<!--IGCMarkupDocument xmlns="http://www.somedomain.com" revision="4" majorversion="0" minorversion="0"-->
<IGCMarkupDocument revision="4" majorversion="0" minorversion="0">
      <PageList pagecount="1">
            <Page index="0">
                  <AuthorList authorcount="1">
                        <Author name="johne">
                              <Text id="0" time="1100715019" color="255,0,0" fontsize="1.60284" italic="false" bold="false" opaque="false" underline="false" font="Arial" hyperlink="">  
                                    <TextLine>text on drawing in markup</TextLine>  
                              </Text>
                              <Changemark id="1" time="1100715030" color="255,0,0" hyperlink="">  
                                    <Title>Description of changemark, for john</Title>  
                                    <Comment>This is the details of the changemarks for Johns Changemark</Comment>
                                    <Viewstate Extents="true">  
                                          <Page>0</Page>  
                                          <ScaleFactor>1.44467</ScaleFactor>  
                                          <Rotation>0.0</Rotation>
                                          <EyePoint>  
                                                <x>367.5</x>  
                                                <y>244.0</y>  
                                          </EyePoint>
                                          <DeviceRect>  
                                                <top>0</top>  
                                                <left>0</left>  
                                                <bottom>706</bottom>  
                                                <right>1157</right>  
                                          </DeviceRect>
                                          <LayerTable LayerCount="1">  
                                                <LayerBlock>1</LayerBlock>  
                                          </LayerTable>  
                                    </Viewstate>  
                              </Changemark>  
                        </Author>  
                  </AuthorList>  
            </Page>  
      </PageList>  
</IGCMarkupDocument>

Than it is as simple as this:

Dim objXml
Dim Nodes
Dim Node

Set objXml = Server.CreateObject("Microsoft.XMLDOM")
objXml.async = False
If objXml.Load("\\casablanca\Public\changemark.xml") Then
   Set Nodes = objXml.selectNodes("IGCMarkupDocument/PageList/Page/AuthorList/Author/Text/TextLine")
   For Each Node In Nodes
           Response.Write "&nbsp;" & Node.Text & "&nbsp;"
   Next
   Set Nodes = Nothing
Else
           Response.Write objXml.parseError.reason
End If
Set objXml = Nothing

If you cannot, than it becomes somewhat more difficult ...
0
 
LVL 11

Author Comment

by:SweatCoder
ID: 12667357
thanks for the response. yes, i can lose the namespace if needed. but from your syntax it appears that i can only retrieve the value for a specific instance of TextLine, with a specifc heirarchy. There may be many instances throughout the document, even though this particular xml doc only has one.

how can i get all instances? is there a way to get all instances of any arbitrary element regardless of its tree depth or location? for example, if i wanted to extract the text of all <FOO></FOO> elements, regardless of position, heirarchy, or whatever, is there a command that will do that? that's really what i'm looking for, because i'm wanting to get more than just <TextLine>. . .i used that as my only example for simplicity.

THANKS.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 12667784
>>how can i get all instances? <<
Change this:
Set Nodes = objXml.selectNodes("IGCMarkupDocument/PageList/Page/AuthorList/Author/Text/TextLine")

To:
Set Nodes = objXml.selectNodes("//TextLine")

or:
Set Nodes = objXml.getElementsByTagName("TextLine")
0
 
LVL 11

Author Comment

by:SweatCoder
ID: 12668482
you're beautiful! works great.
0
 
LVL 11

Author Comment

by:SweatCoder
ID: 12668493
here's the final working implementation, in case it might help somebody else:

SET objXML = Server.CreateObject("Msxml2.DomDocument")
objXml.async = False
PathToXML = Server.MapPath("./changemark.xml")
writeme "PathToXML: " & PathToXML
If objXml.Load(PathToXML) Then
      'Set Nodes = objXml.getElementsByTagName("TextLine")
      Set Nodes = objXml.selectNodes("//TextLine")
      For Each Node In Nodes
            Response.Write "&nbsp;" & Node.Text & "&nbsp;"
      Next
      Set Nodes = Nothing
Else
      Response.Write "ERROR: " & objXml.parseError.reason
End If
Set objXml = Nothing
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question