Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:33:49+00:00 2026-06-07T21:33:49+00:00

The CIPCode element in the following XML is optional: <?xml version=1.0 encoding=utf-8?> <StateCodesList SchoolYear=2012-2013

  • 0

The “CIPCode” element in the following XML is optional:

<?xml version="1.0" encoding="utf-8"?>
<StateCodesList SchoolYear="2012-2013" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CourseCodesList.xsd">
    <Year>2013</Year>
    <Course>
        <StateCode>990001</StateCode>
        <Description>Reading</Description>
        <ShortName>Reading</ShortName>
        <LongName>Reading</LongName>
        <CIPCode>1.01</CIPCode>
        <Type>99</Type>
    </Course>
    <Course>
        <StateCode>9902</StateCode>
        <Description>Math</Description>
        <ShortName>Short</ShortName>
        <LongName>Long</LongName>
        <Type>70</Type>
    </Course>
</StateCodesList>

I have the following code which puts the elements in an Anonymous Type:

Using aStreamReader As New StreamReader(New MemoryStream(criteria.File)) 'File is the XML in Byte() form
    Dim xDoc As System.Xml.Linq.XDocument
    xDoc = System.Xml.Linq.XDocument.Load(aStreamReader)

    '....do some non-relevant stuff here

    Dim courses = From myCourse In xDoc.Descendants("Course")
                    Select New With
                        {
                            .StateCode = myCourse.Element("StateCode").Value, _
                            .Description = myCourse.Element("Description").Value, _
                            .ShortName = myCourse.Element("ShortName").Value, _
                            .LongName = myCourse.Element("LongName").Value, _
                            .Type = myCourse.Element("Type").Value, _
                            .CipCode = myCourse.Element("CIPCode").Value _
                        }
    '....do some non-relevant stuff here
End Using

The code throws an exception (Object reference not set to an instance of an object.) when CIPCode is left out. Is there a way to configure the code so that CIPCode is stored when applicable and no exception get thrown?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:33:50+00:00Added an answer on June 7, 2026 at 9:33 pm

    Is there a way to configure the code so that CIPCode is stored when applicable and no exception get thrown?

    Sure. It’s really easy – just use the explicit conversion to string instead:

    .CipCode = CType(myCourse.Element("CIPCode"), String)
    

    That will give you Nothing when there’s no such element.

    (Note that the VB version of the docs is broken, as it uses the Value property instead…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is state table that have statename and circode but they are not sorted
I use latex to typeset lots of code using the minted package. Mainly the
I have a piece of C++ code that generates the data. I want to
I am creating a stored procedure and I can't for the life of me
I have used a JOIN to put together a query that uses columns from
I am interested in generating a C++ header using Apache Avro's code generation tool
I am trying to import data from an Access database into R. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.