Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to WriteXML as hierarchical XML

From: "Anthony Jones" <Ant@------------.--->
To: 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




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent