Solved

Working with XML

Posted on 2011-03-18
9
476 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

635 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