Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Working with XML

Posted on 2011-03-18
9
Medium Priority
?
483 Views
Last Modified: 2012-05-11
I am trying to use XML to represent a

menu
- submenu
-- subsubmenu


structure.


Here is the entire XML:

<CATALOGS><CATALOG><CATID></CATID><DESC>CLOTHING</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS><CATALOG><CATID></CATID><DESC>MEN'S CLOTHING</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS><CATALOG><CATID>132</CATID><DESC>PANTS</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>134</CATID><DESC>SHORTS</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>136</CATID><DESC>SHIRTS</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG></NAVBARSUBCATS></CATALOG><CATALOG><CATID>140</CATID><DESC>WOMEN'S CLOTHING</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS><CATALOG><CATID>142</CATID><DESC>PANTS</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>144</CATID><DESC>SHORTS</DESC><CONTENTPATH>somefolder/somepage.aspx</CON
TENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>146</CATID><DESC>SHIRTS</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>148</CATID><DESC>ACCESSORIES</DESC><CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG></NAVBARSUBCATS></CATALOG><CATALOG><CATID>140</CATID><DESC>CHILDREN'S CLOTHING</DESC><CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH><NAVBARSUBCATS><CATALOG><CATID>152</CATID><DESC>PANTS</DESC><CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID></CATID><DESC>SHORTS</DESC><CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>156</CATID><DESC>SHIRTS</DESC><CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG><CATALOG><CATID>158</CATID><DESC>TOYS</DESC><CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS></CATALOG></
NAVBARSUBCATS></CATALOG></NAVBARSUBCATS></CATALOG></CATALOGS>

Open in new window




1)  Is it malformed?


2)  I do get a runtime error when I try to fill the DataSet object by reading in the XML:

{System.Data.DuplicateNameException: A column named 'NAVBARSUBCATS' already belongs to this DataTable: cannot set a nested table name to the same name.



{System.Data.DuplicateNameException: A column named 'NAVBARSUBCATS' already belongs to this DataTable: cannot set a nested table name to the same name.
   at System.Data.DataColumnCollection.RegisterColumnName(String name, DataColumn column, DataTable table)
   at System.Data.DataRelation.set_Nested(Boolean value)
   at System.Data.XSDSchema.InstantiateTable(XmlSchemaElement node, XmlSchemaComplexType typeNode, Boolean isRef)
   at System.Data.XSDSchema.HandleTable(XmlSchemaElement node)
   at System.Data.XSDSchema.HandleParticle(XmlSchemaParticle pt, DataTable table, ArrayList tableChildren, Boolean isBase)
   at System.Data.XSDSchema.HandleComplexType(XmlSchemaComplexType ct, DataTable table, ArrayList tableChildren, Boolean isNillable)
   at System.Data.XSDSchema.InstantiateTable(XmlSchemaElement node, XmlSchemaComplexType typeNode, Boolean isRef)
   at System.Data.XSDSchema.HandleTable(XmlSchemaElement node)
   at System.Data.XSDSchema.HandleParticle(XmlSchemaParticle pt, DataTable table, ArrayList tableChildren, Boolean isBase)
   at System.Data.XSDSchema.HandleComplexType(XmlSchemaComplexType ct, DataTable table, ArrayList tableChildren, Boolean isNillable)
   at System.Data.XSDSchema.InstantiateTable(XmlSchemaElement node, XmlSchemaComplexType typeNode, Boolean isRef)
   at System.Data.XSDSchema.HandleTable(XmlSchemaElement node)
   at System.Data.XSDSchema.HandleDataSet(XmlSchemaElement node, Boolean isNewDataSet)
   at System.Data.XSDSchema.LoadSchema(XmlSchemaSet schemaSet, DataSet ds)
   at System.Data.DataSet.InferSchema(XmlDocument xdoc, String[] excludedNamespaces, XmlReadMode mode)
   at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
   at System.Data.DataSet.ReadXml(TextReader reader)
   at Campus_Webstore.NSubCatList.BuildCatalog() in C:\KnowltonCWS\CWS\Website\Campus Webstore\UserControls\NSubCatList.ascx.cs:line 131}

Open in new window




3)  The use and reuse of <NAVBARSUBCATS> everywhere is on purpose.  Can I either get the DataSet to IGNORE or ALLOW the apparent duplicate table names....or is there a more suitable data structure to store the xml in?

Thanks!


Tom
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 35171425
Tom,

Here are my thoughts:

1) I prefer a formatted layout to visualize XML.  It was easy for me to reformat using Visual Studio.NET IDE:

<?xml version="1.0" encoding="utf-8" ?>
<CATALOGS>
  <CATALOG>
    <CATID></CATID>
    <DESC>CLOTHING</DESC>
    <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
    <NAVBARSUBCATS>
      <CATALOG>
        <CATID></CATID>
        <DESC>MEN'S CLOTHING</DESC>
        <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
        <NAVBARSUBCATS>
          <CATALOG>
            <CATID>132</CATID>
            <DESC>PANTS</DESC>
            <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID>134</CATID>
            <DESC>SHORTS</DESC>
            <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID>136</CATID>
            <DESC>SHIRTS</DESC>
            <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
        </NAVBARSUBCATS>
      </CATALOG>
      <CATALOG>
        <CATID>140</CATID>
        <DESC>WOMEN'S CLOTHING</DESC>
        <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
        <NAVBARSUBCATS>
          <CATALOG>
            <CATID>142</CATID>
            <DESC>PANTS</DESC>
            <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID>144</CATID>
            <DESC>SHORTS</DESC>
            <CONTENTPATH>
              somefolder/somepage.aspx</CONTENTPATH><NAVBARSUBCATS></NAVBARSUBCATS>
            </CATALOG>
          <CATALOG>
            <CATID>146</CATID>
            <DESC>SHIRTS</DESC>
            <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID>148</CATID>
            <DESC>ACCESSORIES</DESC>
            <CONTENTPATH>somefolder/somepage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
        </NAVBARSUBCATS>
      </CATALOG>
      <CATALOG>
        <CATID>140</CATID>
        <DESC>CHILDREN'S CLOTHING</DESC>
        <CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH>
        <NAVBARSUBCATS>
          <CATALOG>
            <CATID>152</CATID>
            <DESC>PANTS</DESC>
            <CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID></CATID>
            <DESC>SHORTS</DESC>
            <CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID>156</CATID>
            <DESC>SHIRTS</DESC>
            <CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
          <CATALOG>
            <CATID>158</CATID>
            <DESC>TOYS</DESC>
            <CONTENTPATH>somefolder/sompage.aspx</CONTENTPATH>
            <NAVBARSUBCATS></NAVBARSUBCATS>
          </CATALOG>
      </CATALOG>
    </NAVBARSUBCATS>
  </CATALOG>
</CATALOGS>

Open in new window


2) I see after reformatting that it doesn't have the proper end tag, and I get an error that confirms that:

      Expecting end tag </NAVBARSUBCATS>

3) What version of .NET do you have, because there are a lot better ways in 3.5/4 to work with XML, versus using a DataSet, such as LINQ-to-XML, DataContractSerializer, ...

4) XHTML suggests something that I agree with--lowercase

5) You have a format that is confusing, right from the git' go.  It is not a good practice to have the same element name for elements lower in the hierarchy.

<CATALOGS>
  <CATALOG catid="" desc="CLOTHING" contentPath="somefolder/somepage.aspx">
    <NAVBARSUBCATS>
      <CATALOG>

6) Use attributes, and self-closing tags to reduce the amount of text.

7) I could imagine something like this:

<?xml version="1.0" encoding="utf-8" ?>
<catalogs>
  <content>
    <catalog id="1" title="Summer Sales 2011" url="" />
    <catalog id="2" title="Fall Fling 2011" url="" />
    <catalog id="3" title="Sports and Leisure 2011" url="" />
  </content>
  <categories>
    <category id="1000" title="Seasonal" />
  </categories>
  <navigation>
    <menu menuId="1" type="category" elementId="1000" parentId="" />
    <menu menuId="2" type="catalog" id="1" parent="1" />
    <menu menuId="3" type="catalog" id="2" parent="1" />
    <menu menuId="4" type="catalog" id="3" parent="1" />
  </navigation>
</catalogs>

Open in new window

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 35181827
1)  Thanks for the reformat.

2)  Noted, and thank you!

3)  Visual Studio 2010.  But I don't get LINQ.  To me, LINQ is as difficult to understand as anything preceding it.

4)  I'll make the change!

5)  I didn't know this was not allowed.  I'm open to changing it as long as I can get the results.

6)  No problem here, as long as I can get the results I'm desiring!


I like #7 a lot.  Let me spend some time with it and see if it will do the trick.  As I said, I am attempting to use XML to represent a menu / submenu / sub submenu type structure.  Eventually this will be a left hand side navigation bar on a web page.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 35182009
I am getting illegal characters in path, but the error does not say which characters:

- <catalogs>
- <content>
  <catalog id="1" title="Summer Sales 2011" url="" /> 
  <catalog id="2" title="Fall Fling 2011" url="" /> 
  <catalog id="3" title="Sports and Leisure 2011" url="" /> 
  </content>
- <categories>
  <category id="1000" title="Seasonal" /> 
  </categories>
- <navigation>
  <menu menuId="1" type="category" elementId="1000" parentId="" /> 
  <menu menuId="2" type="catalog" id="1" parent="1" /> 
  <menu menuId="3" type="catalog" id="2" parent="1" /> 
  <menu menuId="4" type="catalog" id="3" parent="1" /> 
  </navigation>
  </catalogs>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 35185598
Tom,

I am not sure what you are showing me, but the text has '-' preceding the node elements.  I imagine that this is a paste from Internet Explorer, but I need to check, since they are invalid characters.  Usually, when you get any errors with XML, it tells you what line and character position.  I would need to know that, in order to help you.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 35185686
Since I posted...I have made it past that issue.

Here is my current XML, which seems to be working okay:


- <catalogs>
- <content>
  <catalog id="1" catid="" menutext="Womens" contenturl="" parentid="" /> 
  <catalog id="2" catid="" menutext="Mens" contenturl="" parentid="" /> 
  <catalog id="3" catid="" menutext="Childrens" contenturl="" parentid="" /> 
  <catalog id="4" catid="" menutext="Hats" contenturl="" parentid="" /> 
  <catalog id="5" catid="" menutext="Accessories" contenturl="" parentid="" /> 
  <catalog id="6" catid="" menutext="Gifts" contenturl="" parentid="" /> 
  <catalog id="7" catid="" menutext="Sweats" contenturl="" parentid="2" /> 
  <catalog id="8" catid="" menutext="Tees" contenturl="" parentid="2" /> 
  <catalog id="9" catid="" menutext="Shorts" contenturl="" parentid="2" /> 
  <catalog id="10" catid="" menutext="Football" contenturl="" parentid="2" /> 
  <catalog id="11" catid="" menutext="Basketball" contenturl="" parentid="2" /> 
  <catalog id="12" catid="" menutext="Accessores" contenturl="" parentid="2" /> 
  <catalog id="13" catid="" menutext="Post Season" contenturl="" parentid="2" /> 
  </content>
  </catalogs>


My new problem is with the jquery accordion now.

Open in new window


0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 35185688
As usual, a terrific job!  :)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 35185708
If you have another unanswered question, you can give me the URL...
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 35185713
Will do.


I am the lone developer at my small company with a deadline.

I could use the help!

Give me just a minute....
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question