Correct XSD to ignore embedded markup with namespaces

Posted on 2009-04-28
Last Modified: 2012-05-06
Long story short, I have the following XML contained in a file (not really, but this models what I am doing):

<myElement name="myElement1">
  <Template Culture="1033">
    <asp:Label ID="Label1" runat="server" Text="Hello World!" />
  <Template Culture="10">
    <asp:Label ID="Label1" runat="server" Text="Hola mundo!" />

I am trying to load the file into a System.Xml.XmlDocument instance so the contents can be parsed.  Unfortunately, .NET throws an exception because it says that "asp" is an unrecognized namespace.  (Btw, an XmlReader is not appropriate because I need bi-directional access to the data.)

My thought is to create an XML Schema definition that tells .NET to treat anything inside a <Template> element as raw text and not try to parse it - I will handle that myself.  So far I have been unable to do so.

I appreciate any help figuring out how to accomplish this.
Question by:SonOfPirate
    1 Comment
    LVL 60

    Accepted Solution

    This is nothing you can solve with an XSD.
    Schema validation needs to happen on a wellformed document.
    So, the wellformedness check comes first and if you don't bind the prefix to a namespace,
    this XML snippet is simply unwellformed (this means it is not XML)
    You can easily tell the validating parser to not care about the content for a specific element,
    if you make the content model xsd:any and validation lax.
    I can show you how if you want to,
    but this will not solve your problem

    you will nee to change your XML like this
    <myElement name="myElement1" xmlns:asp="some-uri-here>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now