SweatCoder
asked on
Microsoft.XMLDOM in asp - get arbitrary nodes
I'm trying to do this in asp, iis5, win2k:
SET objXML = Server.CreateObject("Micro soft.XMLDO M")
objXML.async = False
objXML.load("\\casablanca\ Public\cha ngemark.xm l")
'objXML.loadXML(BinaryBuff er) 'can i load a binary xml stream directly into the xml object?
SET Node = objXML.documentElement.sel ectSingleN ode("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</Scal eFactor>
<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>
SET objXML = Server.CreateObject("Micro
objXML.async = False
objXML.load("\\casablanca\
'objXML.loadXML(BinaryBuff
SET Node = objXML.documentElement.sel
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</Scal
<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>
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you're beautiful! works great.
ASKER
here's the final working implementation, in case it might help somebody else:
SET objXML = Server.CreateObject("Msxml 2.DomDocum ent")
objXml.async = False
PathToXML = Server.MapPath("./changema rk.xml")
writeme "PathToXML: " & PathToXML
If objXml.Load(PathToXML) Then
'Set Nodes = objXml.getElementsByTagNam e("TextLin e")
Set Nodes = objXml.selectNodes("//Text Line")
For Each Node In Nodes
Response.Write " " & Node.Text & " "
Next
Set Nodes = Nothing
Else
Response.Write "ERROR: " & objXml.parseError.reason
End If
Set objXml = Nothing
SET objXML = Server.CreateObject("Msxml
objXml.async = False
PathToXML = Server.MapPath("./changema
writeme "PathToXML: " & PathToXML
If objXml.Load(PathToXML) Then
'Set Nodes = objXml.getElementsByTagNam
Set Nodes = objXml.selectNodes("//Text
For Each Node In Nodes
Response.Write " " & Node.Text & " "
Next
Set Nodes = Nothing
Else
Response.Write "ERROR: " & objXml.parseError.reason
End If
Set objXml = Nothing
<?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</Scal
<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("Micro
objXml.async = False
If objXml.Load("\\casablanca\
Set Nodes = objXml.selectNodes("IGCMar
For Each Node In Nodes
Response.Write " " & Node.Text & " "
Next
Set Nodes = Nothing
Else
Response.Write objXml.parseError.reason
End If
Set objXml = Nothing
If you cannot, than it becomes somewhat more difficult ...