Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Formatting vertically liner xml doc to hierarchy format dynamically in any depth.

Reply
Thread Tools

Formatting vertically liner xml doc to hierarchy format dynamically in any depth.

 
 
Bostonasian
Guest
Posts: n/a
 
      02-14-2007
I don't even know where to begin this as hierarchy is always confusing
to construct dynamically in any form(query, xslt,etc). However it is
very easy to follow when it's presented. I've done breaking a linear
doc to 2 levels of hierarchy before, but that case had fixed level(its
depth didn't go any further than 2).

I have xml doc in attribute oriented format as following :
<Root>
<Survey ID="1" ControlType="Label" ParentID="1" Text="1. Commute"/>
<Survey ID="2" ControlType="Label" ParentID="1" Text="How do you
commute?"/>
<Survey ID="3" ControlType="DropDown" ParentID="2" Text="Car"/>
<Survey ID="4" ControlType="DropDown" ParentID="2" Text="Subway"/>
<Survey ID="5" ControlType="DropDown" ParentID="2" Text="Commuter
Rail"/>
<Survey ID="5" ControlType="DropDown" ParentID="2" Text="Bus"/>
<Survey ID="7" ControlType="DropDown" ParentID="2" Text="Walk"/>
<Survey ID="8" ControlType="Label" ParentID="1" Text="How long is
your commute?"/>
<Survey ID="9" ControlType="DropDown" ParentID="8" Text="-30min"/>
<Survey ID="10" ControlType="DropDown" ParentID="8" Text="30min - 1
hour"/>
<Survey ID="11" ControlType="DropDown" ParentID="8" Text="1 hour+"/>
<Survey ID="12" ControlType="Label" ParentID="12" Text="2. Your
company"/>
<Survey ID="13" ControlType="TextBox" ParentID="12" Text="Company
name"/>
<Survey ID="14" ControlType="TextBox" ParentID="12" Text="Employer"/>
<Survey ID="15" ControlType="TextBox" ParentID="15" Text="3. Other
comment"/>
</Root>

What I need to do is to format above in heirarchy form. If attribute
"ID" and "ParentID" are equal, it means that that node comes on top
level. So far, the depth of the hierarchy doesn't go any deeper than 3
levels. But I can't count on it. So ultimately what I want to have is
following :

<Root>
<Survey ID="1" ControlType="Label" Text="1. Commute">
<Survey ID="2" ControlType="Label" Text="How do you commute?">
<Survey ID="4" ControlType="DropDown" Text="Subway"/>
<Survey ID="5" ControlType="DropDown" Text="Commuter Rail"/>
<Survey ID="5" ControlType="DropDown" Text="Bus"/>
<Survey ID="7" ControlType="DropDown" Text="Walk"/>
</Survey>
<Survey ID="8" ControlType="Label" Text="How long is your commute?">
<Survey ID="9" ControlType="DropDown" Text="-30min"/>
<Survey ID="10" ControlType="DropDown" Text="30min - 1 hour"/>
<Survey ID="11" ControlType="DropDown" Text="1 hour+"/>
</Survey>
</Survey>
<Survey ID="12" ControlType="Label" Text="2. Your company">
<Survey ID="13" ControlType="TextBox" Text="Company name"/>
<Survey ID="14" ControlType="TextBox" Text="Employer"/>
</Survey>
<Survey ID="15" ControlType="TextBox" Text="3. Other comment"/>
</Root>

Has anyone does anything like this? If anyone know how to format
hierarchy in any depth, that'd be great, but I'd like know 3 levels at
least.
Thanks in advance.

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-14-2007
Why not just use the fact that XML is inherently tree-structured, and
let the tree hierarchy be your data hierarchy, rather than trying to
link things with IDs? MUCH easier to process for both machines and humans.

<Root>
<Survey ControlType="Label" Text="1. Commute">
<Survey ControlType="Label" Text="How do you
commute?">
<Survey ControlType="DropDown" Text="Car"/>
<Survey ControlType="DropDown" Text="Subway"/>
</Survey>

.... and so on.

(And actually, I'd argue that specifying that the list is a dropdown
belongs at the level of the LIST rather than on the choices. The first
step in using hierarchy is to define a hierarchy that expresses the
concepts you actually want to work with...)
 
Reply With Quote
 
 
 
 
Bostonasian
Guest
Posts: n/a
 
      02-14-2007
On Feb 14, 11:41 am, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
> Why not just use the fact that XML is inherently tree-structured, and
> let the tree hierarchy be your data hierarchy, rather than trying to
> link things with IDs? MUCH easier to process for both machines and humans.
>
> <Root>
> <Survey ControlType="Label" Text="1. Commute">
> <Survey ControlType="Label" Text="How do you
> commute?">
> <Survey ControlType="DropDown" Text="Car"/>
> <Survey ControlType="DropDown" Text="Subway"/>
> </Survey>
>
> ... and so on.
>
> (And actually, I'd argue that specifying that the list is a dropdown
> belongs at the level of the LIST rather than on the choices. The first
> step in using hierarchy is to define a hierarchy that expresses the
> concepts you actually want to work with...)


Unfortunately the format on the top is what I get from third party and
I do have to work with it. I have no control over "Let's use this
format, screw the one you have".

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-14-2007
Bostonasian wrote:
> Unfortunately the format on the top is what I get from third party


OK, in that case the first step may be to write a stylesheet that
restructures it along more reasonable lines. <smile/> This is a
straightforward grouping problem: For each element, gather all the
elements which refer to it as their parent and move them into it as
children, processing them recursively to gather their children in turn.

Once things are in that form, other processing should be a lot more
straightforward.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Bostonasian
Guest
Posts: n/a
 
      02-14-2007
On Feb 14, 1:13 pm, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
> Bostonasian wrote:
> > Unfortunately the format on the top is what I get from third party

>
> OK, in that case the first step may be to write a stylesheet that
> restructures it along more reasonable lines. <smile/> This is a
> straightforward grouping problem: For each element, gather all the
> elements which refer to it as their parent and move them into it as
> children, processing them recursively to gather their children in turn.
>
> Once things are in that form, other processing should be a lot more
> straightforward.
>
> --
> Joe Kesselman / Beware the fury of a patient man. -- John Dryden


Actually I have that approach already in my mind.
The reason I posted this is because I am having trouble with
explicitly manifesting detail solution(XSLT code to be exact).

 
Reply With Quote
 
roy axenov
Guest
Posts: n/a
 
      02-14-2007
On Feb 14, 6:48 pm, "Bostonasian" <axk...@gmail.com> wrote:
> On Feb 14, 11:41 am, Joseph Kesselman
> <keshlam-nos...@comcast.net> wrote:
>
> > Why not just use the fact that XML is inherently
> > tree-structured, and let the tree hierarchy be your
> > data hierarchy, rather than trying to link things with
> > IDs? MUCH easier to process for both machines and
> > humans.

>
> > <Root>
> > <Survey ControlType="Label" Text="1. Commute">
> > <Survey ControlType="Label" Text="How do you
> > commute?">
> > <Survey ControlType="DropDown" Text="Car"/>
> > <Survey ControlType="DropDown" Text="Subway"/>
> > </Survey>

>
> Unfortunately the format on the top is what I get from
> third party and I do have to work with it. I have no
> control over "Let's use this format, screw the one you
> have".


I would heartily recommend contacting the third party in
question and mildly suggesting to them to hire a borking
XML expert instead of saddling some DBA type with the task
of designing XML schemata.

(Oh, I just can see that: 'Hey Fred, we need to uh do urgh
some um XML stuff. Here, take this XML Expertise In Six
Productive Lunch-Breaks. One of my pointy-haired flunkies
told me it was really great.')

--
roy axenov

 
Reply With Quote
 
Bostonasian
Guest
Posts: n/a
 
      02-14-2007
On Feb 14, 2:41 pm, "roy axenov" <r_axe...@mail.ru> wrote:
> On Feb 14, 6:48 pm, "Bostonasian" <axk...@gmail.com> wrote:
>
>
>
> > On Feb 14, 11:41 am, Joseph Kesselman
> > <keshlam-nos...@comcast.net> wrote:

>
> > > Why not just use the fact that XML is inherently
> > > tree-structured, and let the tree hierarchy be your
> > > data hierarchy, rather than trying to link things with
> > > IDs? MUCH easier to process for both machines and
> > > humans.

>
> > > <Root>
> > > <Survey ControlType="Label" Text="1. Commute">
> > > <Survey ControlType="Label" Text="How do you
> > > commute?">
> > > <Survey ControlType="DropDown" Text="Car"/>
> > > <Survey ControlType="DropDown" Text="Subway"/>
> > > </Survey>

>
> > Unfortunately the format on the top is what I get from
> > third party and I do have to work with it. I have no
> > control over "Let's use this format, screw the one you
> > have".

>
> I would heartily recommend contacting the third party in
> question and mildly suggesting to them to hire a borking
> XML expert instead of saddling some DBA type with the task
> of designing XML schemata.
>
> (Oh, I just can see that: 'Hey Fred, we need to uh do urgh
> some um XML stuff. Here, take this XML Expertise In Six
> Productive Lunch-Breaks. One of my pointy-haired flunkies
> told me it was really great.')
>
> --
> roy axenov


Yes I did try that. But for whatever reason, their turn around time
takes longer than me creating XSLT to transform it. Yes I know, it's
all bureaucratic BS and I am already frustrated with this even before
coding. And again, if that was all possible and have grace period time
to negotiate those issue, I wouldn't have posted this here.

 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-14-2007
Bostonasian wrote:
> The reason I posted this is because I am having trouble with
> explicitly manifesting detail solution(XSLT code to be exact).


Well, I gave you an algorithm, but since you're still lost I'll rephrase
it into a completely untested sketch.

<xsl:stylesheet ... and so on ... >
<xsl:template match="/">
<xsl:apply-templates select="/Root/Survey[@ID=1]"/>
</xsl:template>

<xsl:template match="Survey">
<xsl:copy>
<xsl:apply-template select="@*"/>
<xsl:apply-template select="/Root/Survey[@ParentID=current()/@ID]"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|node">
<xsl:copy>
<xsl:apply-template select="@*|node"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

If you don't immediately understand how this works, I strongly recommend
going back and doing a few basic XSLT tutorials. This really is a
third-homework-assignment level of complexity; maybe earlier depending
on what the prereqs were.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      02-15-2007
Bostonasian wrote:
> Yes I did try that. But for whatever reason, their turn around time
> takes longer than me creating XSLT to transform it. Yes I know, it's
> all bureaucratic BS and I am already frustrated with this even before
> coding. And again, if that was all possible and have grace period
> time to negotiate those issue, I wouldn't have posted this here.


Just make sure you charge them for the time in your invoice.
If they're that stupid, they'll pay anyway because they won't
realise their error.

///Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Format XML Doc from Javascript Scott M. ASP .Net 3 10-08-2009 09:58 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
Converting a org.jdom DOC to org.w3c DOC Praveen Chhangani XML 2 08-07-2003 08:22 AM
Parsing MS Word client doc into server-side doc... John Wallace ASP .Net 0 07-22-2003 06:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57