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 329551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:35:57+00:00 2026-05-12T09:35:57+00:00

I think the solution to my problem is very easy, but i couldn’t fint

  • 0

I think the solution to my problem is very easy, but i couldn’t fint it
So, here is:

I have an XML which have a list of elements with different names, but in sequence.
An example:

<DOC>
 <DOC_OBL_1>
  <TIP_DOC_OBL>1</TIP_DOC_OBL> 
 </DOC_OBL_1>
 <DOC_OBL_2>
  <TIP_DOC_OBL>2</TIP_DOC_OBL> 
 </DOC_OBL_2>
 <DOC_OBL_3>
  <TIP_DOC_OBL>3</TIP_DOC_OBL>  
 </DOC_OBL_3>
</DOC>

So, i have 3 elements: DOC_OBL_1, DOC_OBL_2 and DOC_OBL_3. And yes, there could be number 4, 5, 6, etc.
As you can se, all 3 have the same elements inside(actually, they have a lot of them, but arent important righ now), and I thinked i could declare a general type which could validate this kind of documents.

How can i validate this with an Schema???

I know its a very ugly XML (maybe it isnt standard, please tell me, i dont know), but It’s not my concern to build this document. I just have to parse it, validate it and transform it.

  • 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-05-12T09:35:57+00:00Added an answer on May 12, 2026 at 9:35 am

    Well, sure you can! Pretty simple actually: if the structure is the same for each element, you can define a single <xs:complexType> to validate that, and then use:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="DOC" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="DOC">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="DOC_OBL_1" type="DocType" />
            <xs:element name="DOC_OBL_2" type="DocType" />
            <xs:element name="DOC_OBL_3" type="DocType" />
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:complexType name="DocType">
        <xs:sequence>
          <xs:element name="TIP_DOC_OBL" type="xs:string" minOccurs="0" />
        </xs:sequence>
      </xs:complexType>
    </xs:schema>
    

    Does that work for you? Does it handle all your needs?

    As Zach points out quite correctly – this “solution” obviously is rather limited, since it can’t deal with an arbitrary number of tag DOC_OBL_1, DOC_OBL_2, …., DOC_OBL_x – the name and thus the number of tags must be known ahead of time.

    This is unfortunate, but it’s the only solution, given this crippled XML. The REAL solution would be to have something like:

    <DOC>
      <DOC_OBL id="1">
      </DOC_OBL>
      <DOC_OBL id="2">
      </DOC_OBL>
      .....
      <DOC_OBL id="x">
      </DOC_OBL>
    </DOC>
    

    and then the XML schema would become even easier and could deal with any number of <DOC_OBL> tags.

    But the GIGO principle applies: Garbage In, Garbage Out ==> crappy XML structure comes in, only a crappy, incomplete validation is possible.

    Marc

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

Sidebar

Related Questions

I suspect the solution to my problem to be very easy with LINQ to
First I thought that the problem will be very easy to solve, but it
I can only think of a client-side solution using jQuery, but is it possible
This is an accident and I don't think there's a solution. But I'm asking
Okay, so this seems simple, but I can't think of a straightforward solution; Basically
I have a head aching problem that I can't seem to find an easy
My problem is very simple. I have several folders in my root: [folder1] [folder2]
Okay. I'm sick of this problem. This has to have an easy fix, I'm
I think the solution is really simple, I just haven't come across it online.
I'm trying to think of a solution regarding a way to run existing executables

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.