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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:42:02+00:00 2026-06-10T08:42:02+00:00

I have a sample Xml code snippet <modification name=givenName operation=add xmlns=urn:oasis:names:tc:DSML:2:0:core> <value>Changed name</value> </modification>

  • 0

I have a sample Xml code snippet

<modification name="givenName" operation="add" xmlns="urn:oasis:names:tc:DSML:2:0:core">
    <value>Changed name</value>
</modification> 

The xml is loaded to my XElement, and I used

        XElement xml = ...to load xml above...;
        xml.Should().HaveAttribute("name", "givenName")
            .And.HaveAttribute("operation", "add")
            .And.HaveAttribute("xmlns", "urn:oasis:names:tc:DSML:2:0:core")
            .And.HaveElement("value");

to test my code, the attributes testing are all passed, but the element testing (the last condition) fails.

Anyone can point out what is wrong with my code?

And how can I test the Xml has an element named “value” and its value is “Changed name”?

Thanks in advance!

  • 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-10T08:42:04+00:00Added an answer on June 10, 2026 at 8:42 am

    I suspect the problem is that the XName of the element isn’t just value – it’s value with a namespace. Presumably HaveElement is namespace-aware. Try this:

    XElement xml = ...to load xml above...;
    XNamespace ns = "urn:oasis:names:tc:DSML:2:0:core";
    xml.Should().HaveAttribute("name", "givenName")
        .And.HaveAttribute("operation", "add")
        .And.HaveAttribute("xmlns", "urn:oasis:names:tc:DSML:2:0:core")
        .And.HaveElement(ns + "value");
    

    The last line checks whether it’s got the namespace-qualified element.

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

Sidebar

Related Questions

I have a Sample Code where I'm trying to read data from an xml
I have written simple code to get content from xml file to php. $xml
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have a bit of xml file named Sample.xml which is shown below <?xml
I have been provided an XSD and a sample Xml file that contains the
I have the following XML <ns0:Root xmlns:ns0=http://Map_Sample.Input_Schema> <Number1> </Number1> <Number2>11</Number2> <Number3>12</Number3> </ns0:Root> In this
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
I have the following sample xml in a column of xml data type: <diagnostics
All, I have the below sample XML: <Root> <Sample1>Sample1</Sample1> <Sample2>Sample2</Sample2> <Run> <Entry> <Level1A>Test1</Level1A> <Level1B>Test2</Level1B>
I'm looking for code which can do the following. Given a snippet of XML,

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.