-
Ordering of the attributes
Hi,
I have a problem with the way in which the attributes of a node
appear in the xml file.
Ex
<Node attr1 = "data1" attr33 = "data33" attribute2 = "data2" /Node>
Like the appearnce order of the attributes depends on the length of the name
of the attribute string.
Is there some way, in which I can make the attributes appear in the order
I write them while creating the Xml file???
(I use DOM API with C++)
TIA
Appu
-
Re: Ordering of the attributes
Appu,
Why do you need them in a certain order?
Mark
"Appu" <appu@aol.com> wrote:
>
>Hi,
>
> I have a problem with the way in which the attributes of a node
>appear in the xml file.
>
>Ex
><Node attr1 = "data1" attr33 = "data33" attribute2 = "data2" /Node>
>
>Like the appearnce order of the attributes depends on the length of the
name
>of the attribute string.
>Is there some way, in which I can make the attributes appear in the order
>I write them while creating the Xml file???
>(I use DOM API with C++)
>
>TIA
>Appu
>
-
Re: Ordering of the attributes
Hi Mark,
I want them in a certain order to make them more readable....I want
it to appear in the order I add the attributes to the node....
Appu
"Mark" <mknuttall@nospam.yahoo.com> wrote:
>
>Appu,
> Why do you need them in a certain order?
>
>Mark
>
>"Appu" <appu@aol.com> wrote:
>>
>>Hi,
>>
>> I have a problem with the way in which the attributes of a node
>>appear in the xml file.
>>
>>Ex
>><Node attr1 = "data1" attr33 = "data33" attribute2 = "data2" /Node>
>>
>>Like the appearnce order of the attributes depends on the length of the
>name
>>of the attribute string.
>>Is there some way, in which I can make the attributes appear in the order
>>I write them while creating the Xml file???
>>(I use DOM API with C++)
>>
>>TIA
>>Appu
>>
>
-
Re: Ordering of the attributes
I don't see why they don't appear in the order you are adding them. This
may be parser dependent. When you say DOM and C++ are you saying Microsoft's
parser? How are you creating the xml? Anyway, are you looking at the pure
xml after it is created?
Mark
"Appu" <appu@aol.com> wrote:
>
>Hi Mark,
>
> I want them in a certain order to make them more readable....I want
>it to appear in the order I add the attributes to the node....
>
>Appu
>
>"Mark" <mknuttall@nospam.yahoo.com> wrote:
>>
>>Appu,
>> Why do you need them in a certain order?
>>
>>Mark
>>
>>"Appu" <appu@aol.com> wrote:
>>>
>>>Hi,
>>>
>>> I have a problem with the way in which the attributes of a node
>>>appear in the xml file.
>>>
>>>Ex
>>><Node attr1 = "data1" attr33 = "data33" attribute2 = "data2" /Node>
>>>
>>>Like the appearnce order of the attributes depends on the length of the
>>name
>>>of the attribute string.
>>>Is there some way, in which I can make the attributes appear in the order
>>>I write them while creating the Xml file???
>>>(I use DOM API with C++)
>>>
>>>TIA
>>>Appu
>>>
>>
>
-
Re: Ordering of the attributes
Hi Mark,
I think the problem is with the way DOM stores the attributes.One guy
told me it uses a map(STL) and hence it sorts the attributes before storing
them in the tree.That could be the reason the attributes dont appear in the
order I set them in...
Anyway thanks
Appu
"Mark" <mknuttall@nospam.yahoo.com> wrote:
>
>I don't see why they don't appear in the order you are adding them. This
>may be parser dependent. When you say DOM and C++ are you saying Microsoft's
>parser? How are you creating the xml? Anyway, are you looking at the pure
>xml after it is created?
>
>Mark
>
>"Appu" <appu@aol.com> wrote:
>>
>>Hi Mark,
>>
>> I want them in a certain order to make them more readable....I
want
>>it to appear in the order I add the attributes to the node....
>>
>>Appu
>>
>>"Mark" <mknuttall@nospam.yahoo.com> wrote:
>>>
>>>Appu,
>>> Why do you need them in a certain order?
>>>
>>>Mark
>>>
>>>"Appu" <appu@aol.com> wrote:
>>>>
>>>>Hi,
>>>>
>>>> I have a problem with the way in which the attributes of a node
>>>>appear in the xml file.
>>>>
>>>>Ex
>>>><Node attr1 = "data1" attr33 = "data33" attribute2 = "data2" /Node>
>>>>
>>>>Like the appearnce order of the attributes depends on the length of the
>>>name
>>>>of the attribute string.
>>>>Is there some way, in which I can make the attributes appear in the order
>>>>I write them while creating the Xml file???
>>>>(I use DOM API with C++)
>>>>
>>>>TIA
>>>>Appu
>>>>
>>>
>>
>
-
Re: Ordering of the attributes
When I programmatically create a series of nodes, they appear in the order I
add them using msxml3. This is a VB example, sorry, but it should be easy to
follow. It might help people solve your problem if you post more of your
code and XML as well as state which XML parser and version you're using.
Dim xml As New DOMDocument
Dim i As Integer
Dim N As IXMLDOMNode
Dim natt As IXMLDOMAttribute
' create a simple document
xml.loadXML "<?xml version=""1.0""?><root><node1/></root>"
' get a reference to the node1 node
Set N = xml.selectSingleNode("root/node1")
' create 10 attributes
For i = 1 To 10
' create an attribute
Set natt = xml.createAttribute("att" & CStr(i))
' set its text property
natt.Text = CStr(i)
' append the attribute to node1
N.Attributes.setNamedItem natt
Next
' Print the attribute values
For Each natt In N.Attributes
Debug.Print natt.Text
Next
' Ensure that the generated XML contains these attributes in sequence
Debug.Print N.xml
The code prints the following in the debug window:
1
2
3
4
5
6
7
8
9
10
<node1 att1="1" att2="2" att3="3" att4="4" att5="5" att6="6" att7="7"
att8="8" att9="9" att10="10"/>
"Appu" <appu@aol.com> wrote in message news:3aae347e$1@news.devx.com...
>
> Hi Mark,
>
> I think the problem is with the way DOM stores the attributes.One guy
> told me it uses a map(STL) and hence it sorts the attributes before
storing
> them in the tree.That could be the reason the attributes dont appear in
the
> order I set them in...
>
-
Re: Ordering of the attributes
In your code you have the same attribute names(same lengths), I have problem
with attribute names with different length(like att1, attribute2, myAttribute3)......and
even for same length attribute names, DOM seems to be sorting them in alphabetical
order
And I am using DOM Implementation with Api's from Apache site(xerces
stuff)
Appu
"Russell Jones" <arj1@northstate.net> wrote:
>When I programmatically create a series of nodes, they appear in the order
I
>add them using msxml3. This is a VB example, sorry, but it should be easy
to
>follow. It might help people solve your problem if you post more of your
>code and XML as well as state which XML parser and version you're using.
>
> Dim xml As New DOMDocument
> Dim i As Integer
> Dim N As IXMLDOMNode
> Dim natt As IXMLDOMAttribute
>
> ' create a simple document
> xml.loadXML "<?xml version=""1.0""?><root><node1/></root>"
>
> ' get a reference to the node1 node
> Set N = xml.selectSingleNode("root/node1")
>
> ' create 10 attributes
> For i = 1 To 10
> ' create an attribute
> Set natt = xml.createAttribute("att" & CStr(i))
>
> ' set its text property
> natt.Text = CStr(i)
>
> ' append the attribute to node1
> N.Attributes.setNamedItem natt
> Next
>
> ' Print the attribute values
> For Each natt In N.Attributes
> Debug.Print natt.Text
> Next
>
> ' Ensure that the generated XML contains these attributes in sequence
> Debug.Print N.xml
>
>The code prints the following in the debug window:
>1
>2
>3
>4
>5
>6
>7
>8
>9
>10
><node1 att1="1" att2="2" att3="3" att4="4" att5="5" att6="6" att7="7"
>att8="8" att9="9" att10="10"/>
>
>"Appu" <appu@aol.com> wrote in message news:3aae347e$1@news.devx.com...
>>
>> Hi Mark,
>>
>> I think the problem is with the way DOM stores the attributes.One
guy
>> told me it uses a map(STL) and hence it sorts the attributes before
>storing
>> them in the tree.That could be the reason the attributes dont appear in
>the
>> order I set them in...
>>
>
>
>
-
Re: Ordering of the attributes
Appu,
So you are using Java? I have had the same issue with the HashMap class.
Anyway, how looking at the XML? How are you serializing it with XMLSerializer
or some other method? You can sort the attributes before you print/display
them.
Mark
"Appu" <appu@aol.com> wrote:
>
>In your code you have the same attribute names(same lengths), I have problem
>with attribute names with different length(like att1, attribute2, myAttribute3)......and
>even for same length attribute names, DOM seems to be sorting them in alphabetical
>order
> And I am using DOM Implementation with Api's from Apache site(xerces
>stuff)
>
>Appu
>"Russell Jones" <arj1@northstate.net> wrote:
>>When I programmatically create a series of nodes, they appear in the order
>I
>>add them using msxml3. This is a VB example, sorry, but it should be easy
>to
>>follow. It might help people solve your problem if you post more of your
>>code and XML as well as state which XML parser and version you're using.
>>
>> Dim xml As New DOMDocument
>> Dim i As Integer
>> Dim N As IXMLDOMNode
>> Dim natt As IXMLDOMAttribute
>>
>> ' create a simple document
>> xml.loadXML "<?xml version=""1.0""?><root><node1/></root>"
>>
>> ' get a reference to the node1 node
>> Set N = xml.selectSingleNode("root/node1")
>>
>> ' create 10 attributes
>> For i = 1 To 10
>> ' create an attribute
>> Set natt = xml.createAttribute("att" & CStr(i))
>>
>> ' set its text property
>> natt.Text = CStr(i)
>>
>> ' append the attribute to node1
>> N.Attributes.setNamedItem natt
>> Next
>>
>> ' Print the attribute values
>> For Each natt In N.Attributes
>> Debug.Print natt.Text
>> Next
>>
>> ' Ensure that the generated XML contains these attributes in sequence
>> Debug.Print N.xml
>>
>>The code prints the following in the debug window:
>>1
>>2
>>3
>>4
>>5
>>6
>>7
>>8
>>9
>>10
>><node1 att1="1" att2="2" att3="3" att4="4" att5="5" att6="6" att7="7"
>>att8="8" att9="9" att10="10"/>
>>
>>"Appu" <appu@aol.com> wrote in message news:3aae347e$1@news.devx.com...
>>>
>>> Hi Mark,
>>>
>>> I think the problem is with the way DOM stores the attributes.One
>guy
>>> told me it uses a map(STL) and hence it sorts the attributes before
>>storing
>>> them in the tree.That could be the reason the attributes dont appear
in
>>the
>>> order I set them in...
>>>
>>
>>
>>
>
-
Re: Ordering of the attributes
Mark,
No, I'm not using Java(what made you feel so??).I'm using c++, on a win32
platform and using the DOM Api's.
And by the way, I have solved the problem temporarily, by making the attributes
of a node as its child nodes, ofcourse there's some overhead involved, but
it seems to work as per my design........
rgds
Appu
"Mark" <mknuttall@nospam.yahoo.com> wrote:
>
>Appu,
> So you are using Java? I have had the same issue with the HashMap class.
> Anyway, how looking at the XML? How are you serializing it with XMLSerializer
>or some other method? You can sort the attributes before you print/display
>them.
>
>Mark
>
>"Appu" <appu@aol.com> wrote:
>>
>>In your code you have the same attribute names(same lengths), I have problem
>>with attribute names with different length(like att1, attribute2, myAttribute3)......and
>>even for same length attribute names, DOM seems to be sorting them in alphabetical
>>order
>> And I am using DOM Implementation with Api's from Apache site(xerces
>>stuff)
>>
>>Appu
>>"Russell Jones" <arj1@northstate.net> wrote:
>>>When I programmatically create a series of nodes, they appear in the order
>>I
>>>add them using msxml3. This is a VB example, sorry, but it should be easy
>>to
>>>follow. It might help people solve your problem if you post more of your
>>>code and XML as well as state which XML parser and version you're using.
>>>
>>> Dim xml As New DOMDocument
>>> Dim i As Integer
>>> Dim N As IXMLDOMNode
>>> Dim natt As IXMLDOMAttribute
>>>
>>> ' create a simple document
>>> xml.loadXML "<?xml version=""1.0""?><root><node1/></root>"
>>>
>>> ' get a reference to the node1 node
>>> Set N = xml.selectSingleNode("root/node1")
>>>
>>> ' create 10 attributes
>>> For i = 1 To 10
>>> ' create an attribute
>>> Set natt = xml.createAttribute("att" & CStr(i))
>>>
>>> ' set its text property
>>> natt.Text = CStr(i)
>>>
>>> ' append the attribute to node1
>>> N.Attributes.setNamedItem natt
>>> Next
>>>
>>> ' Print the attribute values
>>> For Each natt In N.Attributes
>>> Debug.Print natt.Text
>>> Next
>>>
>>> ' Ensure that the generated XML contains these attributes in sequence
>>> Debug.Print N.xml
>>>
>>>The code prints the following in the debug window:
>>>1
>>>2
>>>3
>>>4
>>>5
>>>6
>>>7
>>>8
>>>9
>>>10
>>><node1 att1="1" att2="2" att3="3" att4="4" att5="5" att6="6" att7="7"
>>>att8="8" att9="9" att10="10"/>
>>>
>>>"Appu" <appu@aol.com> wrote in message news:3aae347e$1@news.devx.com...
>>>>
>>>> Hi Mark,
>>>>
>>>> I think the problem is with the way DOM stores the attributes.One
>>guy
>>>> told me it uses a map(STL) and hence it sorts the attributes before
>>>storing
>>>> them in the tree.That could be the reason the attributes dont appear
>in
>>>the
>>>> order I set them in...
>>>>
>>>
>>>
>>>
>>
>
-
Re: Ordering of the attributes
Didn't realize they had a C++ parser on the Apache site. Glad it is working.
Mark
"Appu" <appu@aol.com> wrote:
>
>Mark,
>
> No, I'm not using Java(what made you feel so??).I'm using c++, on a win32
>platform and using the DOM Api's.
>And by the way, I have solved the problem temporarily, by making the attributes
>of a node as its child nodes, ofcourse there's some overhead involved, but
>it seems to work as per my design........
>
>rgds
>Appu
>
>"Mark" <mknuttall@nospam.yahoo.com> wrote:
>>
>>Appu,
>> So you are using Java? I have had the same issue with the HashMap class.
>> Anyway, how looking at the XML? How are you serializing it with XMLSerializer
>>or some other method? You can sort the attributes before you print/display
>>them.
>>
>>Mark
>>
>>"Appu" <appu@aol.com> wrote:
>>>
>>>In your code you have the same attribute names(same lengths), I have problem
>>>with attribute names with different length(like att1, attribute2, myAttribute3)......and
>>>even for same length attribute names, DOM seems to be sorting them in
alphabetical
>>>order
>>> And I am using DOM Implementation with Api's from Apache site(xerces
>>>stuff)
>>>
>>>Appu
>>>"Russell Jones" <arj1@northstate.net> wrote:
>>>>When I programmatically create a series of nodes, they appear in the
order
>>>I
>>>>add them using msxml3. This is a VB example, sorry, but it should be
easy
>>>to
>>>>follow. It might help people solve your problem if you post more of your
>>>>code and XML as well as state which XML parser and version you're using.
>>>>
>>>> Dim xml As New DOMDocument
>>>> Dim i As Integer
>>>> Dim N As IXMLDOMNode
>>>> Dim natt As IXMLDOMAttribute
>>>>
>>>> ' create a simple document
>>>> xml.loadXML "<?xml version=""1.0""?><root><node1/></root>"
>>>>
>>>> ' get a reference to the node1 node
>>>> Set N = xml.selectSingleNode("root/node1")
>>>>
>>>> ' create 10 attributes
>>>> For i = 1 To 10
>>>> ' create an attribute
>>>> Set natt = xml.createAttribute("att" & CStr(i))
>>>>
>>>> ' set its text property
>>>> natt.Text = CStr(i)
>>>>
>>>> ' append the attribute to node1
>>>> N.Attributes.setNamedItem natt
>>>> Next
>>>>
>>>> ' Print the attribute values
>>>> For Each natt In N.Attributes
>>>> Debug.Print natt.Text
>>>> Next
>>>>
>>>> ' Ensure that the generated XML contains these attributes in sequence
>>>> Debug.Print N.xml
>>>>
>>>>The code prints the following in the debug window:
>>>>1
>>>>2
>>>>3
>>>>4
>>>>5
>>>>6
>>>>7
>>>>8
>>>>9
>>>>10
>>>><node1 att1="1" att2="2" att3="3" att4="4" att5="5" att6="6" att7="7"
>>>>att8="8" att9="9" att10="10"/>
>>>>
>>>>"Appu" <appu@aol.com> wrote in message news:3aae347e$1@news.devx.com...
>>>>>
>>>>> Hi Mark,
>>>>>
>>>>> I think the problem is with the way DOM stores the attributes.One
>>>guy
>>>>> told me it uses a map(STL) and hence it sorts the attributes before
>>>>storing
>>>>> them in the tree.That could be the reason the attributes dont appear
>>in
>>>>the
>>>>> order I set them in...
>>>>>
>>>>
>>>>
>>>>
>>>
>>
>
-
Re: Ordering of the attributes
"Appu" <appu@aol.com> wrote in message news:3aaf40a0$1@news.devx.com...
>
> In your code you have the same attribute names(same lengths), I have
problem
> with attribute names with different length(like att1, attribute2,
myAttribute3)......and
> even for same length attribute names, DOM seems to be sorting them in
alphabetical
> order
> And I am using DOM Implementation with Api's from Apache
site(xerces
> stuff)
No, I specifically ran the loop from 1 to 10 to ensure that that didn't
happen. The attribute name "att10" is longer than the attribute name "att9",
but that has no effect on the position. Similarly, if the attributes were
being sorted alpabetically by name, the attributes "att1" and "att10" would
appear sequentially, before "att2" -- but that doesn't happen either.
Therefore, the current msxml3 parser maintains attributes in document order.
However, you're not using the msxml parser. The Xerces parser apparently
does not maintain attributes in document order. There's nothing improper
about that. The XML spec says that parsers do not have to maintain
attributes in document order--that the order of attributes within an element
is not considered important to XML.
Russell Jones
Sr. Web Development Editor
DevX.com
-
Re: Ordering of the attributes
FYI this thread is probobly dead but here is an exerpt from the MS XML Parser
SDK docs:
"Because the order in which attributes appeared inside of an element is not
considered important by XML, it may not be preserved by the XML parser."
"Mark" <mknuttall@nospam.yahoo.com> wrote:
>
>Didn't realize they had a C++ parser on the Apache site. Glad it is working.
>
>Mark
>
>"Appu" <appu@aol.com> wrote:
>>
>>Mark,
>>
>> No, I'm not using Java(what made you feel so??).I'm using c++, on a win32
>>platform and using the DOM Api's.
>>And by the way, I have solved the problem temporarily, by making the attributes
>>of a node as its child nodes, ofcourse there's some overhead involved,
but
>>it seems to work as per my design........
>>
>>rgds
>>Appu
>>
>>"Mark" <mknuttall@nospam.yahoo.com> wrote:
>>>
>>>Appu,
>>> So you are using Java? I have had the same issue with the HashMap class.
>>> Anyway, how looking at the XML? How are you serializing it with XMLSerializer
>>>or some other method? You can sort the attributes before you print/display
>>>them.
>>>
>>>Mark
>>>
>>>"Appu" <appu@aol.com> wrote:
>>>>
>>>>In your code you have the same attribute names(same lengths), I have
problem
>>>>with attribute names with different length(like att1, attribute2, myAttribute3)......and
>>>>even for same length attribute names, DOM seems to be sorting them in
>alphabetical
>>>>order
>>>> And I am using DOM Implementation with Api's from Apache site(xerces
>>>>stuff)
>>>>
>>>>Appu
>>>>"Russell Jones" <arj1@northstate.net> wrote:
>>>>>When I programmatically create a series of nodes, they appear in the
>order
>>>>I
>>>>>add them using msxml3. This is a VB example, sorry, but it should be
>easy
>>>>to
>>>>>follow. It might help people solve your problem if you post more of
your
>>>>>code and XML as well as state which XML parser and version you're using.
>>>>>
>>>>> Dim xml As New DOMDocument
>>>>> Dim i As Integer
>>>>> Dim N As IXMLDOMNode
>>>>> Dim natt As IXMLDOMAttribute
>>>>>
>>>>> ' create a simple document
>>>>> xml.loadXML "<?xml version=""1.0""?><root><node1/></root>"
>>>>>
>>>>> ' get a reference to the node1 node
>>>>> Set N = xml.selectSingleNode("root/node1")
>>>>>
>>>>> ' create 10 attributes
>>>>> For i = 1 To 10
>>>>> ' create an attribute
>>>>> Set natt = xml.createAttribute("att" & CStr(i))
>>>>>
>>>>> ' set its text property
>>>>> natt.Text = CStr(i)
>>>>>
>>>>> ' append the attribute to node1
>>>>> N.Attributes.setNamedItem natt
>>>>> Next
>>>>>
>>>>> ' Print the attribute values
>>>>> For Each natt In N.Attributes
>>>>> Debug.Print natt.Text
>>>>> Next
>>>>>
>>>>> ' Ensure that the generated XML contains these attributes in sequence
>>>>> Debug.Print N.xml
>>>>>
>>>>>The code prints the following in the debug window:
>>>>>1
>>>>>2
>>>>>3
>>>>>4
>>>>>5
>>>>>6
>>>>>7
>>>>>8
>>>>>9
>>>>>10
>>>>><node1 att1="1" att2="2" att3="3" att4="4" att5="5" att6="6" att7="7"
>>>>>att8="8" att9="9" att10="10"/>
>>>>>
>>>>>"Appu" <appu@aol.com> wrote in message news:3aae347e$1@news.devx.com...
>>>>>>
>>>>>> Hi Mark,
>>>>>>
>>>>>> I think the problem is with the way DOM stores the attributes.One
>>>>guy
>>>>>> told me it uses a map(STL) and hence it sorts the attributes before
>>>>>storing
>>>>>> them in the tree.That could be the reason the attributes dont appear
>>>in
>>>>>the
>>>>>> order I set them in...
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks