Hur hämtar jag ut värdet för typen mimeCode, alltså "image/tiff" i taggen cbc:EmbeddedDocumentBinaryObject, samt värdet i taggen cbc:EmbeddedDocumentBinaryObject med alla namespace? Tack det funkar!XML Load - Hämta värde
Jag använder mig av ett C# projekt..
<?xml version="1.0" encoding="utf-8"?>
<Document xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 UBL-Invoice-2.0.xsd" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:sdt="urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2">
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
<cac:AdditionalDocumentReference>
<cbc:ID>13291990059B00117</cbc:ID>
<cbc:CopyIndicator>true</cbc:CopyIndicator>
<cbc:DocumentTypeCode listAgencyName="Data Scanning">Indskannet</cbc:DocumentTypeCode>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="image/tiff">Test</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
</Document>Sv: XML Load - Hämta värde
public static void DoIt()
{
var xml = new XmlDocument();
xml.LoadXml(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Document xsi:schemaLocation=""urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 UBL-Invoice-2.0.xsd"" xmlns=""urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:cac=""urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"" xmlns:ccts=""urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2"" xmlns:sdt=""urn:oasis:names:specification:ubl:schema:xsd:SpecializedDatatypes-2"" xmlns:cbc=""urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"" xmlns:udt=""urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2"">
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
<cac:AdditionalDocumentReference>
<cbc:ID>13291990059B00117</cbc:ID>
<cbc:CopyIndicator>true</cbc:CopyIndicator>
<cbc:DocumentTypeCode listAgencyName=""Data Scanning"">Indskannet</cbc:DocumentTypeCode>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode=""image/tiff"">Test</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
</Document>");
var namespaceManager = new XmlNamespaceManager(xml.NameTable);
namespaceManager.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
namespaceManager.AddNamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
// TODO: Error handling
var mimeType = xml.SelectSingleNode("//cbc:EmbeddedDocumentBinaryObject", namespaceManager).Attributes["mimeCode"].Value;
}
Sv:XML Load - Hämta värde
Men jag försökte med ett annat exempel men får inte det att funka..
Vill få ut värde i tagen Id i min C# men får det inte att funka.
<?xml version="1.0" encoding="iso-8859-1"?>
<Change xmlns="http://www.test3.no/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.test3.no/XMLSchema Change.xsd">
<Header>
<Version>1.0</Version>
<Id>4638</Id>
<Time>2013-07-19T06:07:59</Time>
</Header>
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
manager.AddNamespace("foo", "http://www.test3.no/XMLSchema");
XmlNodeList listtype = doc.SelectNodes("//foo:" + "Change/Header/Id, manager);