Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - How to WriteXML as hierarchical XML [Thread Next] Re: How to WriteXML as hierarchical XMLTo: NULL Date: 3/1/2006 3:01:00 PM
> I want to make a hierarchical XML form the view.
> The XML is like below
>
> How can I do?
>
>
> the view:
>
> Area Employee
> ----------------------------------------
> North Mary
> North John
> North Max
> East Kai
> West Jina
> West John
> South Tim
> South Peter
>
> the hierarchical XML
>
> <?xml version="1.0"?>
> <AreaEmployee>
> <Area>
> North
> <Employee>
> Mary
> </Employee>
> </Area>
> <Area>
> North
> <Employee>
> John
> </Employee>
> </Area>
> <Area>
> North
> <Employee>
> Max
> </Employee>
> </Area>
<snip>
>
> ,,..............................
>
> </AreaEmployee>
>
First of this isn't a good XML structure for carrying data. An Area node
would look better as:-
<areaEmployee>
<area>
<name>North</name>
<employee>Mary</employee>
<employee>John</employee>
</area>
<area>
<name>West</name>
<employee>Jina</employee>
<employee>John</employee>
</area>
</areaEmployee>
Given a recordset rs holding your results:-
VBScript:-
Dim oXML: Set oXML = CreateObject("MSXML2.DOMDocument.3.0")
Dim oArea
Dim oEmp
Dim sAreaCur
oXML.LoadXML "<areaEmployee />"
Do Until rs.EOF
If rs("Area") <> sArea Then
sAreaCur = rs("Area")
Set oArea = AddElem(oXML, "area")
AddElem oArea, "name", sAreaCur
End If
AddElem oArea, "employee", rs("Employee")
Loop
'oXML now contains what you need
Function AddElem(Parent, Name, Value)
AddElement = Parent.ownerDocument.createElement(Name)
If Not IsNull(Value) AddElement.Text = CStr(Value)
End Function
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
