I have an XML file with IP addresses and their assigned locations/floors that looks like this:
<Locations>
<LOCATION1>
<FLOOR1>
<SECTION1>
<IP>10.10.10.10</IP>
<IP>etc....
</SECTION1>
</FLOOR1>
</LOCATION1>
.....
What I am attempting to do is get query for an IP address and return the names of the parent elements. I am able to query for that IP but I have not had any luck figuring out how to get the parent elements names (i.e. SECTION1, FLOOR1, LOCATION1). Here is the code I am using for querying xml to find the IP, I just have it returning the value at the moment to verify my query was successful:
var query = from t in xmlLocation.Descendants("IP")
where t.Value.Equals(sIP)
select t.Value;
Try this :
XML
<?xml version="1.0" encoding="utf-8" ?>
<Locations>
<LOCATION1>
<FLOOR1>
<SECTION1>
<IP>10.10.10.10</IP>
<IP>20.20.20.20</IP>
</SECTION1>
</FLOOR1>
<FLOOR2>
<SECTION1>
<IP>30.30.30.30</IP>
<IP>40.40.40.40</IP>
</SECTION1>
</FLOOR2>
</LOCATION1>
</Locations >
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
var results = doc.Descendants("LOCATION1").Elements().Select(x => new
{
parent = x.Name.ToString(),
ip = x.Descendants("IP").Select(y => (string)y).ToList()
}).ToList();
}
}
}
The code below gets location, floor, and section
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
var results = doc.Descendants("Locations").Elements().Select(x => x.Elements().Select(y => y.Elements().Select(z => new {
location = x.Name.ToString(),
floor = y.Name.ToString(),
section = z.Name.ToString(),
ip = z.Descendants("IP").Select(i => (string)i).ToList()
})).SelectMany(a => a)).SelectMany(b => b).ToList();
}
}
}
var xDoc = XDocument.Load(filename);
var ip = xDoc.XPathSelectElement("//IP['10.10.10.10']");
var names = ip.Ancestors().Select(a => a.Name.LocalName).ToList();
names will contain SECTION1, FLOOR1, LOCATION1, Locations
If you know those name beforehand you can also use them to select the correct node
var ip = xDoc.XPathSelectElement("//LOCATION1/FLOOR1/SECTION1/IP['10.10.10.10']");
or
var section = xDoc.XPathSelectElement("//LOCATION1/FLOOR1/SECTION1[IP['10.10.10.10']]");
Related
I need your help to finish my task also gain some knowledge from it.
I am having XMl like below
<?xml version="1.0" encoding="UTF-8"?>
<spml:batchRequest xmlns:subscriber="urn:abc:names:prov:gw:SUBSCRIBER:3:0" xmlns:spml="urn:abc:names:prov:gw:SPML:2:0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" execution="synchronous" timestamp="true" processing="sequential" onError="exit_commit">
<version>SUBSCRIBER_v30</version>
<request xsi:type="spml:ModifyRequest" returnResultingObject="full">
<version>SUBSCRIBER_v30</version>
<objectclass>Subscriber</objectclass>
<identifier>1234567890</identifier>
<modification name="udm5gData/servingPlmnId[#plmnId='20201']/provisionedData/sessionManagementSubscriptionData[#singleNssai='1-000002']/dnnConfiguration[#dnnId='dj.nmdd']" operation="remove" scope="uniqueTypeMapping" xmlns:subscriber="urn:abc:names:prov:gw:SUBSCRIBER:3:0">
</modification>
</request>
</spml:batchRequest>
Out of this I need to modify the #singleNssai='1-000002' from modification tag Could anyone help me to change.
Something like #singleNssai='2-000001'
I am trying like below
XmlDataDocument doc = new XmlDataDocument();
doc.Load("D:\\soaptemp\\test.xml");
XmlNode singlenssais =
doc.SelectSingleNode("//modification/name/#singleNssai");
if (singlenssais != null)
{
singlenssais.Value = "2-000001"; // Set to new value.
}
Using Xml Linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication40
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement modification = doc.Descendants("modification").First();
XAttribute name = modification.Attribute("name");
string strName = (string)name;
strName = strName.Replace("1-000002", "2-000001");
name.SetValue(strName);
}
}
}
What do you think the correct XPath is to pull the dublin core identifier below?
I added a namespace manager with these entries:
// Add the namespace.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(m_xml.NameTable);
nsmgr.AddNamespace("mets", "http://www.loc.gov/METS/");
nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
nsmgr.AddNamespace("dcterms", "http://purl.org/dc/terms/");
And I have tried 15 or so different XPath iterations including the ones below. When I do not get an error, the result is null.
//xml_uuid = m_xml.SelectSingleNode("/mets:mets/mets:dmdSec/mets:mdWrap/mets:xmlData/dcterms:dublincore/dc:identifier").Value;
xml_uuid = m_xml.SelectSingleNode("//dc:identifier",nsmgr).Value;
Here is the xml I am working with:
<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/version18/mets.xsd">
<mets:metsHdr CREATEDATE="2017-03-08T20:13:27" />
<mets:dmdSec ID="dmdSec_1">
<mets:mdWrap MDTYPE="DC">
<mets:xmlData>
<dcterms:dublincore xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xsi:schemaLocation="http://purl.org/dc/terms/ http://dublincore.org/schemas/xmls/qdc/2008/02/11/dcterms.xsd">
<dc:identifier>F2015.5</dc:identifier>
</dcterms:dublincore>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
etc...
I am trying to assign the dc:identifier - F2015.5 in this case - to a string.
With xml linq and ignoring the namespaces :
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication131
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
string results = (string)doc.Descendants().Where(x => x.Name.LocalName == "identifier").FirstOrDefault();
}
}
}
Here is one working answer. I believe the main thing is to use .InnerText and not .Value.
xml_uuid = m_xml.SelectSingleNode("//mets:xmlData[1]/dcterms:dublincore[1]/dc:identifier[1]", nsmgr).InnerText;
I have this XML File
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Mobiles>
<Mobile ID="98a2d0b9c2661725a7486423ebd94abdef53ed89051ff5ac7a9c63a4b2a99d7a" RegDate="26/05/2017">
<FullName>Galaxy S-4</FullName>
<Vendor>Samsung</Vendor>
<Date>2010</Date>
<Price>30000SYP</Price>
<Weight>5g</Weight>
<Features>All</Features>
<Notifecations></Notifecations>
<Picture>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADCAQQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hp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qxciPF/Dfwpv7idLjXkS0tV5a3Vg0r+xIyqj3BJ+nWvYoYo4YUiiVViRQqqvQAdAKmpKhyb3KSSFrzr4lfDC18cwJeW8q2eswLsjmZfklXqFfHOM9GHIyeD0r0WikM+PtU+G3jjQpmWXQbydS3+sso/PVvf5MkD6gVlnTNdi/4+NP1KD/f09/8K+1aK09oyeVHxOIbr+N51/7cWp6QzvIqLdy7mbaq/YXJY+gAHJr7VpMU/a+QcqPi0W100mxLiRnZtqr9hkzn0A29aPJuPu/a5d33dv2GT/CvtKil7RhynxcIL1/9VLct/u6e9S/2N4im/wBVp+sy/wDXPTXGfxxX2bRR7Rhyo+RNH+FHjPWpF8rRZ7RGPzTaj+5C+5B+b8lNfQnw8+Hdh4E06QJJ9p1K5A+03TLjgdEUdlH5k8nsB21LUuTY0rBRRRUjCiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//2Q==</Picture>
</Mobile>
<Mobile ID='00283f5aa9c0c68c342c02977051757a7faae0ee70b086e628da7cc5baef2100' RegDate="26/05/2017">
<FullName>6600</FullName>
<Vendor>Nokia</Vendor>
<Date>2006</Date>
<Price>200SYP</Price>
<Weight>10g</Weight>
<Features>blutooth</Features>
<Notifecations></Notifecations>
<Picture>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABbAEUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAk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P8AY3iW5hK/6Nct9rhGOzffH5lvzFcvoGuWuga/p8UiyR/Z5CjyRSMrSRv1yQc4HysOexr2b4s+Hf7X8JSXtuha80wNOm0ZZkx86j8ADj/ZFfO+pD7ZpsN9GoLwYSTjqvb+opkM+gXbNvJbtNqKsAGyiTEGUEHn5TgZA7k1EjLOwaKxup4ZMMBL5mCCMnIfC5zWH4F12LXdGtFbUFXUYRtkjlUZIUYVvvLuyAB3II5rZuLYQtMbu4XABBZI1QBQdyjLMw/j447UIRVJZ4bZLxyyoqoLWJiSMEDAIGA3HRQTxwRUXwbONS1ePttU/r/9eql5rdtp8Ej2BZ5A5IumYnGTnAfoRyRtQYOOcVo/CCxljn1W7ZCiMETkdCecfXGD/wACFNlI9ZoooqSgooooAayhhggEHqD3r5v8b+CbzwZrdzdWlk914fvCchRuEQPJVvTHY9MY719I0YHpQJo+U9K0S3uQJrSe8aBvuoNPkmz+KjFdvpXhvUxtNroepTt03C0itQP+BSkH8ga92ooFynmtn4B1K6nWbUJbWyUf3P8ASZ/wZgFX8FNd5pum22lWK2topWMckscsxPUk9yfWrtFBQtFFFAH/2Q==</Picture>
</Mobile>
</Mobiles>
When I try to remove Mobile element depending on IDtextbox.text rather than static value in XPath expression it doesn't execute
I'm using Windows application in Visual Studio 2010, C# language
I need two examples:
1- Depending on an element inside the parent element.
2- depending on an attribute of the parent element, make sure that attribute is not an integer value, it's code.
Notice: I have searched for many websites and view multiple solutions nobody mention about using control value in XPath expressions.
Use xml linq which is better in this case than xpath
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
List<XElement> mobiles = doc.Descendants("Mobile").ToList();
mobiles = mobiles.Where(x => (string)x.Element("FullName") != "Galaxy S-4").ToList();
mobiles = mobiles.Where(x => (string)x.Attribute("RegDate") != "26/05/2017").ToList();
doc.Descendants("Mobiles").FirstOrDefault().ReplaceWith(new XElement("Mobiles", mobiles));
}
}
}
thanks, Mr.jdweng
I solve the problem with this code
XDocument doc = XDocument.Load(#"Mobiles.xml");
List<XElement> mobiles = doc.Descendants("Mobile").ToList();
//mobiles = mobiles.Where(x => (string)x.Element("ID") == ID).ToList();
mobiles = mobiles.Where(x => (string)x.Attribute("ID") == ID).ToList();
doc.Descendants("Mobile").FirstOrDefault().ReplaceWith();
Best regards
I am trying to extract the following values from this XML using C#.
Messages - the inntertext
success="true" - just the "true" bit
status="Released" - just the "Released" bit
Namespaces are clearly the issue here - but I can't get it right.
Can someone provide an example of parsing this file here please?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<tns:executeCreateLoanIncreaseResponse xmlns:tns="http://api.ws.liq.pisys.com/">
<CreateLoanIncreaseResponse success="true">
<OutstandingTransactionAsReturnValue version="1.0" alias="LIBRLC" status="Released" id="5CJB6GS"></OutstandingTransactionAsReturnValue>
<Messages>
<Message>CreateLoanIncrease>>Effective date current business date (08-Sep-2016).</Message>
<Message>CreateLoanIncrease>>Intent Notices have not been generated.</Message>
<Message>CreateLoanIncrease>>You are about to release this increase.</Message>
</Messages>
</CreateLoanIncreaseResponse>
</tns:executeCreateLoanIncreaseResponse>
</soapenv:Body>
</soapenv:Envelope>
Try xml linq :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
XElement messages = doc.Descendants().Where(x => x.Name.LocalName == "Messages").FirstOrDefault();
XNamespace ns = messages.GetDefaultNamespace();
List<string> strMessages = messages.Elements(ns + "Message").Select(x => (string)x).ToList();
}
}
}
You can use Linq2Xml and XPath
var xDoc = XDocument.Load(filename);
var success = (bool)xDoc.XPathSelectElement("//CreateLoanIncreaseResponse").Attribute("success");
var status = (string)xDoc.XPathSelectElement("//OutstandingTransactionAsReturnValue").Attribute("status");
var messages = xDoc.XPathSelectElements("//Message").Select(x => (string)x.Value).ToList();
When an item is bought with Buy It Now and immediate payment, my code is being triggered correctly (the code sends me an email to test it).
What I want is the ebay item id of the item sold which I believe is here (found this sample in the documentation):
<GetItemTransactionsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2015-07-02T00:09:03.273Z</Timestamp>
<Ack>Success</Ack>
<Version>967</Version>
<Build>E967_CORE_BUNDLED_11481347_R1</Build>
<PaginationResult>
<TotalNumberOfPages>1</TotalNumberOfPages>
<TotalNumberOfEntries>1</TotalNumberOfEntries>
</PaginationResult>
<HasMoreTransactions>false</HasMoreTransactions>
<TransactionsPerPage>100</TransactionsPerPage>
<PageNumber>1</PageNumber>
<ReturnedTransactionCountActual>1</ReturnedTransactionCountActual>
<Item>
<AutoPay>false</AutoPay>
<Currency>USD</Currency>
**<ItemID>110048746230</ItemID>**
I'm using the eBay API:
public void EbayCall(GetItemTransactionsResponseType response)
Is that the correct object to expect? I can't see why response.ReturnedTransactionCountActual is 0. Also response.Item.ItemID is null.
response.Ack returns Success.
What am I doing wrong?
Looks like you are getting an xml response. The ID is shown as 110048746230. The xml can easily be parsed in c#. I sued XML Linq below with Load(string FILENAME) method but you can use a string with Parse(string XML) method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication3
{
class Program
{
const string FILENAME = #"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
string itemID = (string)doc.Descendants().Where(x => x.Name.LocalName == "ItemID").FirstOrDefault();
}
}
}