locked
Cant Parse XML with Schema details RRS feed

  • Question

  • User1536523983 posted

    I am extracting data from an XML using the following code:

            Dim doc As XmlDocument = New XmlDocument()
            doc.Load("d:/test2.xml")
     
            Dim Competency As XmlNode
            Dim nodeList As XmlNodeList
            Dim root As XmlNode = doc.DocumentElement
     
            nodeList = root.SelectNodes("descendant::Competency/attribute::name")
     
            'Get Each Org
            For Each Competency In nodeList
                MsgBox(Competency.LastChild.InnerText)
            Next
    Here is the namespace part of the xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <Resume xmlns="http://ns.hr-xml.org/2006-02-28" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="EN" xsi:schemaLocation="http://ns.hr-xml.org/2006-02-28 Resume.xsd">
    If I replace the above with just : 
    <?xml version="1.0" encoding="UTF-8"?>
    <Resume>
    It works perfectly. What am I missing with regards to the name space.
    Tuesday, February 6, 2018 9:31 AM

All replies

  • User-832373396 posted

    Hi ASPNewbie,

    Your code looks like

    Dim doc As XmlDocument = New XmlDocument()
    doc.Load("d:/test2.xml")
    Dim Competency As XmlNode
    Dim nodeList As XmlNodeList
    Dim root As XmlNode = doc.DocumentElement
    nodeList = root.SelectNodes("descendant::Competency/attribute::name")
    
    For Each Competency In nodeList
    MsgBox(Competency.LastChild.InnerText)

     data 

    <?xml version="1.0" encoding="UTF-8"?>
    <Resume xmlns="http://ns.hr-xml.org/2006-02-28" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xml:lang="EN" xsi:schemaLocation="http://ns.hr-xml.org/2006-02-28 Resume.xsd">

    and 

    <?xml version="1.0" encoding="UTF-8"?> <Resume>

    Sir, after debugging on my local in c#, it seems that no effort with them.

                XmlDocument doc = new XmlDocument();           
                doc.Load(@"C:\aa.xml");
                XmlNode Competency;
                XmlNodeList nodeList;
                XmlNode root = doc.DocumentElement;

    and 

    <?xml version="1.0" encoding="utf-8"?>
    
    
      <Data  xmlns="http://ns.hr-xml.org/2006-02-28" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xml:lang="EN" xsi:schemaLocation="http://ns.hr-xml.org/2006-02-28 Resume.xsd">
        <Country>
          <Name>USA</Name>
          <Population>1000</Population>
          <Money>DOLLAR</Money>
          <Cities>
            <CityName>NEWYORK</CityName>
            <AreaCode>560</AreaCode>
          </Cities>
          <Cities>
            <CityName>WASHINGTON</CityName>
            <AreaCode>450</AreaCode>
          </Cities>
        </Country>
        <Country>
          <Name>FRA</Name>
          <Population>300</Population>
          <Money>EURO</Money>
          <Cities>
            <CityName>PARIS</CityName>
            <AreaCode>860</AreaCode>
          </Cities>
          <Cities>
            <CityName>LYON</CityName>
            <AreaCode>40</AreaCode>
          </Cities>
        </Country>
      </Data>
    

    and

    <?xml version="1.0" encoding="utf-8"?>
    
    
      <Data  >
        <Country>
          <Name>USA</Name>
          <Population>1000</Population>
          <Money>DOLLAR</Money>
          <Cities>
            <CityName>NEWYORK</CityName>
            <AreaCode>560</AreaCode>
          </Cities>
          <Cities>
            <CityName>WASHINGTON</CityName>
            <AreaCode>450</AreaCode>
          </Cities>
        </Country>
        <Country>
          <Name>FRA</Name>
          <Population>300</Population>
          <Money>EURO</Money>
          <Cities>
            <CityName>PARIS</CityName>
            <AreaCode>860</AreaCode>
          </Cities>
          <Cities>
            <CityName>LYON</CityName>
            <AreaCode>40</AreaCode>
          </Cities>
        </Country>
      </Data>
    

    So, I suggest that you could check it again and debug step by step using F11.

    Set a breakpoint, then F11, step by step.

    Because, now, the question point may be in your logic layer, I can't help.

    Guide

     start the app with the debugger attached include F11 (step into code), F10 (step over code), or by using Run to Cursor. See the other sections in this topic for info on what these options do.

    Start debugging

    Or you post your full test data to us :)

    With regards, Angelina Jolie 

    Thursday, February 8, 2018 8:10 AM