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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:17:31+00:00 2026-05-28T01:17:31+00:00

I’m trying to read through an XML (Actually a GML, but I don’t think

  • 0

I’m trying to read through an XML (Actually a GML, but I don’t think that makes a difference) and have been running into issues with parsing. This is my first brush with dealing in XML.

My code in C#

void ParseXML(String path)
{
    XmlReader reader = XmlReader.Create( new FileStream( path, FileMode.Open ) );

    reader.Read();

    while( reader.Read() )
    {
        // Only detect start elements.
        if ( reader.IsStartElement() && reader.Name == "gml:featureMember" )
        {
            Debug.Log(reader.Name);
            reader.ReadToDescendant("gml:featureMember");
            Debug.Log(reader["ogr:X"]);
        }
    }
}

A section from the GML I’m working with:

  <gml:featureMember>
    <ogr:fence_neighbors fid="F1">
      <ogr:Name>Xyz Xyz</ogr:Name>
      <ogr:X>2353.45361911000</ogr:X>
      <ogr:Y>-4652.36641288000</ogr:Y>
    </ogr:fence_neighbors>
  </gml:featureMember>

Making this slightly more difficult is that I am working without access to System.Xml.Linq (Unity3D). I get reader.Name just fine, but reader[“ogr:X”] always comes up null. It seems like I’m not using ReadToDescendant and Reader properly, but I’m not quite sure where to start.

  • 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-28T01:17:32+00:00Added an answer on May 28, 2026 at 1:17 am

    The XmlReader does not know about the namespace prefixes as you’re using them.

    Here is a test program that does what I think you’re after. Note that the namespace URI is given explicitly.

    using System;
    using System.IO;
    using System.Xml;
    
    
    class SOTest {
    
        static void Main(string[] args) {
            ParseXML(args[0]);
        }
    
        static void ParseXML(String path)
        {
            XmlReader reader = XmlReader.Create( new FileStream( path, FileMode.Open ) );
    
            reader.Read();
    
            while( reader.Read() )
            {
                // Only detect start elements.
                if ( reader.IsStartElement() && reader.LocalName == "featureMember" && reader.NamespaceURI == "gml-namespace-uri" )
                {
                    Console.WriteLine(reader.Name);
                    reader.ReadToDescendant("X", "ogr-namespace-uri");
                    Console.WriteLine(reader.ReadInnerXml());
                }
            }
        }
    }
    

    I added declarations to the source document for testing:

    <?xml version="1.0" encoding="utf-8"?>
    <wrapper xmlns:gml="gml-namespace-uri" xmlns:ogr="ogr-namespace-uri">
      <gml:featureMember>
        <ogr:fence_neighbors fid="F1">
          <ogr:Name>Xyz Xyz</ogr:Name>
          <ogr:X>2353.45361911000</ogr:X>
          <ogr:Y>-4652.36641288000</ogr:Y>
        </ogr:fence_neighbors>
      </gml:featureMember>
    </wrapper>
    

    The output is simply

    gml:featureMember
    2353.45361911000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.